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,
};
#[test]
fn list() {
assert_eq!(
micromark(
"A paragraph\nwith two lines.\n\n indented code\n\n> A block quote."
),
"
A paragraph\nwith two lines.
\nindented code\n
\n\nA block quote.
\n
",
"should support documents"
);
assert_eq!(
micromark("1. a\n b.\n\n c\n\n > d."),
"\n- \n
a\nb.
\nc\n
\n\nd.
\n
\n \n
",
"should support documents in list items"
);
// To do: list (indent).
// assert_eq!(
// micromark("- one\n\n two"),
// "\ntwo
",
// "should not support 1 space for a two-character list prefix"
// );
// To do: list (indent).
// assert_eq!(
// micromark("- a\n\n b"),
// "",
// "should support blank lines in list items"
// );
// To do: list (indent).
// assert_eq!(
// micromark(" - one\n\n two"),
// "\n two\n
",
// "should support indented code after lists"
// );
assert_eq!(
micromark(" > > 1. one\n>>\n>> two"),
"\n\n\n- \n
one
\ntwo
\n \n
\n
\n
",
"should support proper indent mixed w/ block quotes (1)"
);
// To do: list (indent).
// assert_eq!(
// micromark(">>- one\n>>\n > > two"),
// "\n\n\ntwo
\n
\n
",
// "should support proper indent mixed w/ block quotes (2)"
// );
assert_eq!(
micromark("-one\n\n2.two"),
"-one
\n2.two
",
"should not support a missing space after marker"
);
// To do: list (indent).
// assert_eq!(
// micromark("- foo\n\n\n bar"),
// "",
// "should support multiple blank lines between items"
// );
assert_eq!(
micromark("1. foo\n\n ```\n bar\n ```\n\n baz\n\n > bam"),
"\n- \n
foo
\nbar\n
\nbaz
\n\nbam
\n
\n \n
",
"should support flow in items"
);
// To do: list (indent).
// assert_eq!(
// micromark("- Foo\n\n bar\n\n\n baz"),
// "\n- \n
Foo
\nbar\n\n\nbaz\n
\n \n
",
// "should support blank lines in indented code in items"
// );
assert_eq!(
micromark("123456789. ok"),
"\n- ok
\n
",
"should support start on the first list item"
);
assert_eq!(
micromark("1234567890. not ok"),
"1234567890. not ok
",
"should not support ordered item values over 10 digits"
);
assert_eq!(
micromark("0. ok"),
"\n- ok
\n
",
"should support ordered item values of `0`"
);
assert_eq!(
micromark("003. ok"),
"\n- ok
\n
",
"should support ordered item values starting w/ `0`s"
);
assert_eq!(
micromark("-1. not ok"),
"-1. not ok
",
"should not support “negative” ordered item values"
);
// To do: list (indent).
// assert_eq!(
// micromark("- foo\n\n bar"),
// "",
// "should support indented code in list items (1)"
// );
// To do: list (indent).
// assert_eq!(
// micromark(" 10. foo\n\n bar"),
// "\n- \n
foo
\nbar\n
\n \n
",
// "should support indented code in list items (2)"
// );
assert_eq!(
micromark(" indented code\n\nparagraph\n\n more code"),
"indented code\n
\nparagraph
\nmore code\n
",
"should support indented code in list items (3)"
);
// To do: list (indent).
// assert_eq!(
// micromark("1. indented code\n\n paragraph\n\n more code"),
// "\n- \n
indented code\n
\nparagraph
\nmore code\n
\n \n
",
// "should support indented code in list items (4)"
// );
// To do: list (indent).
// assert_eq!(
// micromark("1. indented code\n\n paragraph\n\n more code"),
// "\n- \n
indented code\n
\nparagraph
\nmore code\n
\n \n
",
// "should support indented code in list items (5)"
// );
assert_eq!(
micromark(" foo\n\nbar"),
"foo
\nbar
",
"should support indented code in list items (6)"
);
// To do: list (indent).
// assert_eq!(
// micromark("- foo\n\n bar"),
// "\nbar
",
// "should support indented code in list items (7)"
// );
// To do: list (indent).
// assert_eq!(
// micromark("- foo\n\n bar"),
// "",
// "should support indented code in list items (8)"
// );
// To do: list (blank).
// assert_eq!(
// micromark("-\n foo\n-\n ```\n bar\n ```\n-\n baz"),
// "\n- foo
\n- \n
bar\n
\n \n- \n
baz\n
\n \n
",
// "should support blank first lines (1)"
// );
// To do: list (blank).
// assert_eq!(
// micromark("- \n foo"),
// "",
// "should support blank first lines (2)"
// );
assert_eq!(
micromark("-\n\n foo"),
"\nfoo
",
"should support empty only items"
);
// To do: list (“blank” lines).
// assert_eq!(
// micromark("- foo\n-\n- bar"),
// "",
// "should support empty continued items"
// );
// To do: list (“blank” lines).
// assert_eq!(
// micromark("- foo\n- \n- bar"),
// "",
// "should support blank continued items"
// );
// To do: list (“blank” lines).
// assert_eq!(
// micromark("1. foo\n2.\n3. bar"),
// "\n- foo
\n\n- bar
\n
",
// "should support empty continued items (ordered)"
// );
assert_eq!(
micromark("*"),
"",
"should support a single empty item"
);
assert_eq!(
micromark("foo\n*\n\nfoo\n1."),
"foo\n*
\nfoo\n1.
",
"should not support empty items to interrupt paragraphs"
);
// To do: list (indent).
// assert_eq!(
// micromark(
// " 1. A paragraph\n with two lines.\n\n indented code\n\n > A block quote."
// ),
// "\n- \n
A paragraph\nwith two lines.
\nindented code\n
\n\nA block quote.
\n
\n \n
",
// "should support indenting w/ 1 space"
// );
// To do: list (indent).
// assert_eq!(
// micromark(
// " 1. A paragraph\n with two lines.\n\n indented code\n\n > A block quote."
// ),
// "\n- \n
A paragraph\nwith two lines.
\nindented code\n
\n\nA block quote.
\n
\n \n
",
// "should support indenting w/ 2 spaces"
// );
// To do: list (indent).
// assert_eq!(
// micromark(
// " 1. A paragraph\n with two lines.\n\n indented code\n\n > A block quote."
// ),
// "\n- \n
A paragraph\nwith two lines.
\nindented code\n
\n\nA block quote.
\n
\n \n
",
// "should support indenting w/ 3 spaces"
// );
assert_eq!(
micromark(
" 1. A paragraph\n with two lines.\n\n indented code\n\n > A block quote."
),
"1. A paragraph\n with two lines.\n\n indented code\n\n > A block quote.\n
",
"should not support indenting w/ 4 spaces"
);
// To do: list (indent).
// assert_eq!(
// micromark(
// " 1. A paragraph\nwith two lines.\n\n indented code\n\n > A block quote."
// ),
// "\n- \n
A paragraph\nwith two lines.
\nindented code\n
\n\nA block quote.
\n
\n \n
",
// "should support lazy lines"
// );
assert_eq!(
micromark(" 1. A paragraph\n with two lines."),
"\n- A paragraph\nwith two lines.
\n
",
"should support partially lazy lines"
);
assert_eq!(
micromark("> 1. > Blockquote\ncontinued here."),
"\n\n- \n
\nBlockquote\ncontinued here.
\n
\n \n
\n
",
"should support lazy lines combined w/ other containers"
);
assert_eq!(
micromark("> 1. > Blockquote\n> continued here."),
"\n\n- \n
\nBlockquote\ncontinued here.
\n
\n \n
\n
",
"should support partially continued, partially lazy lines combined w/ other containers"
);
// To do: list (indent).
// assert_eq!(
// micromark("- foo\n - bar\n - baz\n - boo"),
// "",
// "should support sublists w/ enough spaces (1)"
// );
// To do: list (indent).
// assert_eq!(
// micromark("- foo\n - bar\n - baz\n - boo"),
// "",
// "should not support sublists w/ too few spaces"
// );
assert_eq!(
micromark("10) foo\n - bar"),
"\n- foo\n\n
\n
",
"should support sublists w/ enough spaces (2)"
);
assert_eq!(
micromark("10) foo\n - bar"),
"\n- foo
\n
\n",
"should not support sublists w/ too few spaces (2)"
);
assert_eq!(
micromark("- - foo"),
"",
"should support sublists (1)"
);
assert_eq!(
micromark("1. - 2. foo"),
"\n- \n\n
\n
",
"should support sublists (2)"
);
// To do: list (indent?).
// assert_eq!(
// micromark("- # Foo\n- Bar\n ---\n baz"),
// "",
// "should support headings in list items"
// );
assert_eq!(
micromark("- foo\n- bar\n+ baz"),
"\n",
"should support a new list by changing the marker (unordered)"
);
assert_eq!(
micromark("1. foo\n2. bar\n3) baz"),
"\n- foo
\n- bar
\n
\n\n- baz
\n
",
"should support a new list by changing the marker (ordered)"
);
assert_eq!(
micromark("Foo\n- bar\n- baz"),
"Foo
\n",
"should support interrupting a paragraph"
);
// To do: list (interrupt paragraph).
// assert_eq!(
// micromark("a\n2. b"),
// "a\n2. b
",
// "should not support interrupting a paragraph with a non-1 numbered item"
// );
assert_eq!(
micromark("\n2. a"),
"\n- a
\n
",
"should “interrupt” a blank line (1)"
);
assert_eq!(
micromark("a\n\n2. b"),
"a
\n\n- b
\n
",
"should “interrupt” a blank line (2)"
);
assert_eq!(
micromark("a\n1. b"),
"a
\n\n- b
\n
",
"should support interrupting a paragraph with a 1 numbered item"
);
assert_eq!(
micromark("- foo\n\n- bar\n\n\n- baz"),
"\n- \n
foo
\n \n- \n
bar
\n \n- \n
baz
\n \n
",
"should support blank lines between items (1)"
);
// To do: list (indent).
// assert_eq!(
// micromark("- foo\n - bar\n - baz\n\n\n bim"),
// "",
// "should support blank lines between items (2)"
// );
assert_eq!(
micromark_with_options("- foo\n- bar\n\n\n\n- baz\n- bim", DANGER),
"\n\n",
"should support HTML comments between lists"
);
assert_eq!(
micromark_with_options("- foo\n\n notcode\n\n- foo\n\n\n\n code", DANGER),
"\n- \n
foo
\nnotcode
\n \n- \n
foo
\n \n
\n\ncode\n
",
"should support HTML comments between lists and indented code"
);
// To do: list (indent).
// assert_eq!(
// micromark("- a\n - b\n - c\n - d\n - e\n - f\n- g"),
// "",
// "should not support lists in lists w/ too few spaces (1)"
// );
// To do: list (whitespace, tight).
// assert_eq!(
// micromark("1. a\n\n 2. b\n\n 3. c"),
// "\n- \n
a
\n \n- \n
b
\n \n- \n
c
\n \n
",
// "should not support lists in lists w/ too few spaces (2)"
// );
// To do: list (indent).
// assert_eq!(
// micromark("- a\n - b\n - c\n - d\n - e"),
// "",
// "should not support lists in lists w/ too few spaces (3)"
// );
// To do: list (seen as seeveral lists?).
// assert_eq!(
// micromark("1. a\n\n 2. b\n\n 3. c"),
// "\n- \n
a
\n \n- \n
b
\n \n
\n3. c\n
",
// "should not support lists in lists w/ too few spaces (3)"
// );
assert_eq!(
micromark("- a\n- b\n\n- c"),
"",
"should support loose lists w/ a blank line between (1)"
);
// To do: list (multiple blank lines).
// assert_eq!(
// micromark("* a\n*\n\n* c"),
// "",
// "should support loose lists w/ a blank line between (2)"
// );
// To do: list (indent).
// assert_eq!(
// micromark("- a\n- b\n\n c\n- d"),
// "\n- \n
a
\n \n- \n
b
\nc
\n \n- \n
d
\n \n
",
// "should support loose lists w/ a blank line in an item (1)"
// );
// To do: list (indent).
// assert_eq!(
// micromark("- a\n- b\n\n [ref]: /url\n- d"),
// "",
// "should support loose lists w/ a blank line in an item (2)"
// );
// To do: list (indent).
// assert_eq!(
// micromark("- a\n- ```\n b\n\n\n ```\n- c"),
// "",
// "should support tight lists w/ a blank line in fenced code"
// );
// To do: list (indent).
// assert_eq!(
// micromark("- a\n - b\n\n c\n- d"),
// "",
// "should support tight lists w/ a blank line in a sublist"
// );
// To do: list (indent).
// assert_eq!(
// micromark("* a\n > b\n >\n* c"),
// "",
// "should support tight lists w/ a blank line in a block quote"
// );
// To do: list (indent).
// assert_eq!(
// micromark("- a\n > b\n ```\n c\n ```\n- d"),
// "",
// "should support tight lists w/ flow w/o blank line"
// );
assert_eq!(
micromark("- a"),
"",
"should support tight lists w/ a single content"
);
// To do: list (indent).
// assert_eq!(
// micromark("- a\n - b"),
// "",
// "should support tight lists w/ a sublist"
// );
// To do: list (indent).
// assert_eq!(
// micromark("1. ```\n foo\n ```\n\n bar"),
// "\n- \n
foo\n
\nbar
\n \n
",
// "should support loose lists w/ a blank line in an item"
// );
// To do: list (blank lines).
// assert_eq!(
// micromark("* foo\n * bar\n\n baz"),
// "",
// "should support loose lists w/ tight sublists (1)"
// );
// To do: list (blank lines).
// assert_eq!(
// micromark("- a\n - b\n - c\n\n- d\n - e\n - f"),
// "",
// "should support loose lists w/ tight sublists (2)"
// );
// Extra.
// To do: list (empty).
// assert_eq!(
// micromark("* a\n*\n\n \n\t\n* b"),
// "",
// "should support continued list items after an empty list item w/ many blank lines"
// );
// To do: list (indent).
// assert_eq!(
// micromark("*\n ~~~p\n\n ~~~"),
// "",
// "should support blank lines in code after an initial blank line"
// );
assert_eq!(
micromark(
"* a tight item that ends with an html element: `x`\n\nParagraph"
),
"\n- a tight item that ends with an html element:
x
\n
\nParagraph
",
"should ignore line endings after tight items ending in tags"
);
// To do: list (empty).
// assert_eq!(
// micromark("* foo\n\n*\n\n* bar"),
// "",
// "should support empty items in a spread list"
// );
// To do: list (slurp?).
// assert_eq!(
// micromark("- ```\n\n ```"),
// "",
// "should remove indent of code (fenced) in list (0 space)"
// );
// To do: list (slurp?).
// assert_eq!(
// micromark("- ```\n \n ```"),
// "",
// "should remove indent of code (fenced) in list (1 space)"
// );
// To do: list (slurp?).
// assert_eq!(
// micromark("- ```\n \n ```"),
// "",
// "should remove indent of code (fenced) in list (2 spaces)"
// );
// To do: list (slurp?).
// assert_eq!(
// micromark("- ```\n \n ```"),
// "",
// "should remove indent of code (fenced) in list (3 spaces)"
// );
// To do: list (slurp?).
// assert_eq!(
// micromark("- ```\n \n ```"),
// "",
// "should remove indent of code (fenced) in list (4 spaces)"
// );
// To do: list (slurp?).
// assert_eq!(
// micromark("- ```\n\t\n ```"),
// "",
// "should remove indent of code (fenced) in list (1 tab)"
// );
// To do: list (empty).
// assert_eq!(
// micromark("- +\n-"),
// "",
// "should support complex nested and empty lists (1)"
// );
// To do: list (empty).
// assert_eq!(
// micromark("- 1.\n-"),
// "",
// "should support complex nested and empty lists (2)"
// );
// To do: list (empty).
// assert_eq!(
// micromark("* - +\n* -"),
// "",
// "should support complex nested and empty lists (3)"
// );
assert_eq!(
micromark_with_options("* a\n\n\n\n* b", DANGER),
"\n\n",
"should support the common list breaking comment method"
);
// To do: turning things off.
// assert_eq!(
// micromark("- one\n\n two", {extensions: [{disable: {null: ["list"]}}]}),
// "- one
\ntwo
",
// "should support turning off lists"
// );
}