diff options
author | Titus Wormer <tituswormer@gmail.com> | 2022-06-16 19:04:16 +0200 |
---|---|---|
committer | Titus Wormer <tituswormer@gmail.com> | 2022-06-16 19:04:16 +0200 |
commit | 60ea2fd3a09f10fa28bf48575736b47afebf3221 (patch) | |
tree | f7aae5cec9181f7ff5df23e648fe1da22a94209f /tests | |
parent | ef14d6581848ba5052d3389bb61fc96645551eef (diff) | |
download | markdown-rs-60ea2fd3a09f10fa28bf48575736b47afebf3221.tar.gz markdown-rs-60ea2fd3a09f10fa28bf48575736b47afebf3221.tar.bz2 markdown-rs-60ea2fd3a09f10fa28bf48575736b47afebf3221.zip |
Add heading (setext)
Diffstat (limited to 'tests')
-rw-r--r-- | tests/character_escape.rs | 2 | ||||
-rw-r--r-- | tests/code_fenced.rs | 11 | ||||
-rw-r--r-- | tests/code_indented.rs | 11 | ||||
-rw-r--r-- | tests/heading_setext.rs | 279 | ||||
-rw-r--r-- | tests/thematic_break.rs | 11 |
5 files changed, 295 insertions, 19 deletions
diff --git a/tests/character_escape.rs b/tests/character_escape.rs index c81760d..9e2a5c8 100644 --- a/tests/character_escape.rs +++ b/tests/character_escape.rs @@ -24,7 +24,7 @@ fn character_escape() { assert_eq!( micromark( - "\\*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\\ö 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\\ö not a character entity" ), "<p>*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</p>", "should escape other constructs" diff --git a/tests/code_fenced.rs b/tests/code_fenced.rs index 82ac088..0e19637 100644 --- a/tests/code_fenced.rs +++ b/tests/code_fenced.rs @@ -136,12 +136,11 @@ fn code_fenced() { "should support interrupting paragraphs" ); - // To do: setext. - // assert_eq!( - // micromark("foo\n---\n~~~\nbar\n~~~\n# baz"), - // "<h2>foo</h2>\n<pre><code>bar\n</code></pre>\n<h1>baz</h1>", - // "should support interrupting other content" - // ); + assert_eq!( + micromark("foo\n---\n~~~\nbar\n~~~\n# baz"), + "<h2>foo</h2>\n<pre><code>bar\n</code></pre>\n<h1>baz</h1>", + "should support interrupting other content" + ); assert_eq!( micromark("```ruby\ndef foo(x)\n return 3\nend\n```"), diff --git a/tests/code_indented.rs b/tests/code_indented.rs index f21d761..a7afb21 100644 --- a/tests/code_indented.rs +++ b/tests/code_indented.rs @@ -53,12 +53,11 @@ fn code_indented() { "should support paragraphs directly after indented code" ); - // To do: setext. - // assert_eq!( - // micromark("# Heading\n foo\nHeading\n------\n foo\n----"), - // "<h1>Heading</h1>\n<pre><code>foo\n</code></pre>\n<h2>Heading</h2>\n<pre><code>foo\n</code></pre>\n<hr />", - // "should mix w/ other content" - // ); + assert_eq!( + micromark("# Heading\n foo\nHeading\n------\n foo\n----"), + "<h1>Heading</h1>\n<pre><code>foo\n</code></pre>\n<h2>Heading</h2>\n<pre><code>foo\n</code></pre>\n<hr />", + "should mix w/ other content" + ); assert_eq!( micromark(" foo\n bar"), diff --git a/tests/heading_setext.rs b/tests/heading_setext.rs new file mode 100644 index 0000000..92a5b43 --- /dev/null +++ b/tests/heading_setext.rs @@ -0,0 +1,279 @@ +extern crate micromark; +use micromark::micromark; + +#[test] +fn heading_setext() { + // To do: emphasis. + // assert_eq!( + // micromark("Foo *bar*\n========="), + // "<h1>Foo <em>bar</em></h1>", + // "should support a heading w/ an equals to (rank of 1)" + // ); + + // To do: emphasis. + // assert_eq!( + // micromark("Foo *bar*\n---------"), + // "<h2>Foo <em>bar</em></h2>", + // "should support a heading w/ a dash (rank of 2)" + // ); + + // To do: emphasis. + // assert_eq!( + // micromark("Foo *bar\nbaz*\n===="), + // "<h1>Foo <em>bar\nbaz</em></h1>", + // "should support line endings in setext headings" + // ); + + // To do: emphasis, trim. + // assert_eq!( + // micromark(" Foo *bar\nbaz*\t\n===="), + // "<h1>Foo <em>bar\nbaz</em></h1>", + // "should not include initial and final whitespace around content" + // ); + + assert_eq!( + micromark("Foo\n-------------------------"), + "<h2>Foo</h2>", + "should support long underlines" + ); + + assert_eq!( + micromark("Foo\n="), + "<h1>Foo</h1>", + "should support short underlines" + ); + + assert_eq!( + micromark(" Foo\n ==="), + "<h1>Foo</h1>", + "should support indented content w/ 1 space" + ); + + assert_eq!( + micromark(" Foo\n---"), + "<h2>Foo</h2>", + "should support indented content w/ 2 spaces" + ); + + assert_eq!( + micromark(" Foo\n---"), + "<h2>Foo</h2>", + "should support indented content w/ 3 spaces" + ); + + assert_eq!( + micromark(" Foo\n ---"), + "<pre><code>Foo\n---\n</code></pre>", + "should not support too much indented content (1)" + ); + + assert_eq!( + micromark(" Foo\n---"), + "<pre><code>Foo\n</code></pre>\n<hr />", + "should not support too much indented content (2)" + ); + + assert_eq!( + micromark("Foo\n ---- "), + "<h2>Foo</h2>", + "should support initial and final whitespace around the underline" + ); + + assert_eq!( + micromark("Foo\n ="), + "<h1>Foo</h1>", + "should support whitespace before underline" + ); + + // To do: trim paragraphs. + // assert_eq!( + // micromark("Foo\n ="), + // "<p>Foo\n=</p>", + // "should not support too much whitespace before underline (1)" + // ); + + // To do: trim paragraphs. + // assert_eq!( + // micromark("Foo\n\t="), + // "<p>Foo\n=</p>", + // "should not support too much whitespace before underline (2)" + // ); + + assert_eq!( + micromark("Foo\n= ="), + "<p>Foo\n= =</p>", + "should not support whitespace in the underline (1)" + ); + + assert_eq!( + micromark("Foo\n--- -"), + "<p>Foo</p>\n<hr />", + "should not support whitespace in the underline (2)" + ); + + // To do: trim setext. + // assert_eq!( + // micromark("Foo \n-----"), + // "<h2>Foo</h2>", + // "should not support a hard break w/ spaces at the end" + // ); + + assert_eq!( + micromark("Foo\\\n-----"), + "<h2>Foo\\</h2>", + "should not support a hard break w/ backslash at the end" + ); + + assert_eq!( + micromark("`Foo\n----\n`"), + "<h2>`Foo</h2>\n<p>`</p>", + "should precede over inline constructs (1)" + ); + + assert_eq!( + micromark("<a title=\"a lot\n---\nof dashes\"/>"), + "<h2><a title="a lot</h2>\n<p>of dashes"/></p>", + "should precede over inline constructs (2)" + ); + + // To do: block quote. + // assert_eq!( + // micromark("> Foo\n---"), + // "<blockquote>\n<p>Foo</p>\n</blockquote>\n<hr />", + // "should not allow underline to be lazy (1)" + // ); + + // To do: block quote. + // assert_eq!( + // micromark("> foo\nbar\n==="), + // "<blockquote>\n<p>foo\nbar\n===</p>\n</blockquote>", + // "should not allow underline to be lazy (2)" + // ); + + // To do: list. + // assert_eq!( + // micromark("- Foo\n---"), + // "<ul>\n<li>Foo</li>\n</ul>\n<hr />", + // "should not allow underline to be lazy (3)" + // ); + + assert_eq!( + micromark("Foo\nBar\n---"), + "<h2>Foo\nBar</h2>", + "should support line endings in setext headings" + ); + + assert_eq!( + micromark("---\nFoo\n---\nBar\n---\nBaz"), + "<hr />\n<h2>Foo</h2>\n<h2>Bar</h2>\n<p>Baz</p>", + "should support adjacent setext headings" + ); + + assert_eq!( + micromark("\n===="), + "<p>====</p>", + "should not support empty setext headings" + ); + + assert_eq!( + micromark("---\n---"), + "<hr />\n<hr />", + "should prefer other constructs over setext headings (1)" + ); + + // To do: list. + // assert_eq!( + // micromark("- foo\n-----"), + // "<ul>\n<li>foo</li>\n</ul>\n<hr />", + // "should prefer other constructs over setext headings (2)" + // ); + + assert_eq!( + micromark(" foo\n---"), + "<pre><code>foo\n</code></pre>\n<hr />", + "should prefer other constructs over setext headings (3)" + ); + + // To do: block quote. + // assert_eq!( + // micromark("> foo\n-----"), + // "<blockquote>\n<p>foo</p>\n</blockquote>\n<hr />", + // "should prefer other constructs over setext headings (4)" + // ); + + assert_eq!( + micromark("\\> foo\n------"), + "<h2>> foo</h2>", + "should support starting w/ character escapes" + ); + + assert_eq!( + micromark("Foo\nbar\n---\nbaz"), + "<h2>Foo\nbar</h2>\n<p>baz</p>", + "paragraph and heading interplay (1)" + ); + + assert_eq!( + micromark("Foo\n\nbar\n---\nbaz"), + "<p>Foo</p>\n<h2>bar</h2>\n<p>baz</p>", + "paragraph and heading interplay (2)" + ); + + assert_eq!( + micromark("Foo\nbar\n\n---\n\nbaz"), + "<p>Foo\nbar</p>\n<hr />\n<p>baz</p>", + "paragraph and heading interplay (3)" + ); + + assert_eq!( + micromark("Foo\nbar\n* * *\nbaz"), + "<p>Foo\nbar</p>\n<hr />\n<p>baz</p>", + "paragraph and heading interplay (4)" + ); + + assert_eq!( + micromark("Foo\nbar\n\\---\nbaz"), + "<p>Foo\nbar\n---\nbaz</p>", + "paragraph and heading interplay (5)" + ); + + // Extra: + assert_eq!( + micromark("Foo \nbar\n-----"), + "<h2>Foo<br />\nbar</h2>", + "should support a hard break w/ spaces in between" + ); + + assert_eq!( + micromark("Foo\\\nbar\n-----"), + "<h2>Foo<br />\nbar</h2>", + "should support a hard break w/ backslash in between" + ); + + assert_eq!( + micromark("a\n-\nb"), + "<h2>a</h2>\n<p>b</p>", + "should prefer a setext heading over an interrupting list" + ); + + // To do: block quote. + // assert_eq!( + // micromark("> ===\na"), + // "<blockquote>\n<p>===\na</p>\n</blockquote>", + // "should not support lazyness (1)" + // ); + + // To do: block quote. + // assert_eq!( + // micromark("> a\n==="), + // "<blockquote>\n<p>a\n===</p>\n</blockquote>", + // "should not support lazyness (2)" + // ); + + // To do: turning things off. + // assert_eq!( + // micromark("a\n-", {extensions: [{disable: {null: ["setextUnderline"]}}]}), + // "<p>a\n-</p>", + // "should support turning off setext underlines" + // ); +} diff --git a/tests/thematic_break.rs b/tests/thematic_break.rs index 3dc7b5d..cbc84e0 100644 --- a/tests/thematic_break.rs +++ b/tests/thematic_break.rs @@ -144,12 +144,11 @@ fn thematic_break() { "should support thematic breaks interrupting paragraphs" ); - // To do: setext. - // assert_eq!( - // micromark("Foo\n---\nbar"), - // "<h2>Foo</h2>\n<p>bar</p>", - // "should not support thematic breaks w/ dashes interrupting paragraphs (setext heading)" - // ); + assert_eq!( + micromark("Foo\n---\nbar"), + "<h2>Foo</h2>\n<p>bar</p>", + "should not support thematic breaks w/ dashes interrupting paragraphs (setext heading)" + ); // To do: list. // assert_eq!( |