test/devcenter-parser_test.rb in devcenter-parser-1.4.9 vs test/devcenter-parser_test.rb in devcenter-parser-2.0.0

- old
+ new

@@ -5,67 +5,44 @@ describe 'DevcenterParser' do describe '.to_unsanitized_html' do it 'returns empty string for nil input' do - assert_parsing_unsanitized_result nil, :maruku, '' - assert_parsing_unsanitized_result nil, :maruku, '' + assert_parsing_unsanitized_result nil, '' end it 'maintains script tags' do - md = '<script>alert("hi")</script>' - assert_parsing_unsanitized_result md, :maruku, '<script><![CDATA[alert("hi")]]></script>' - assert_parsing_unsanitized_result md, :github, '<script>alert("hi")</script>' + assert_parsing_unsanitized_result '<script>alert("hi")</script>', '<script>alert("hi")</script>' end it 'maintains toolbelt custom element' do - md = '<toolbelt />' - assert_parsing_unsanitized_result md, :maruku, '<toolbelt></toolbelt>' - assert_parsing_unsanitized_result md, :github, '<p><toolbelt></toolbelt></p>' + assert_parsing_unsanitized_result '<toolbelt />', '<p><toolbelt></toolbelt></p>' end - it 'maintains custom attributes' do - md = '<p data-next-message="foo">hi</p>' - assert_parsing_unsanitized_result md, :maruku, '<p data-next-message="foo">hi</p>' - assert_parsing_unsanitized_result md, :github, '<p data-next-message="foo">hi</p>' - end - end describe '.to_html' do it 'returns empty string for nil input' do - assert_maruku_result nil, '' - assert_github_result nil, '' + assert_parsing_result nil, '' end it 'does not create <em>s inside words' do - md = 'foo_bar_baz' - html = '<p>foo_bar_baz</p>' - assert_maruku_result md, html - assert_github_result md, html + assert_parsing_result 'foo_bar_baz', '<p>foo_bar_baz</p>' end - it 'raises InvalidMarkdownError when parsing invalid markdown' do - md = '[foo](bar' - assert_raises DevcenterParser::InvalidMarkdownError do - DevcenterParser.to_html(md, :maruku) - end - end - it 'removes script tags and their content' do md = '<strong>clean<script>alert("hack!")</script></strong>' html = '<p><strong>clean</strong></p>' - assert_maruku_result md, html - assert_github_result md, html + assert_parsing_result md, html end it 'allows embedding vimeo videos' do src = <<-SRC <iframe src=\"https://player.vimeo.com/video/61044807?title=0&amp;byline=0&amp;portrait=0&amp;color=a086ee\" width=\"500\" height=\"281\" frameborder=\"0\" webkitallowfullscreen mozallowfullscreen allowfullscreen></iframe> SRC - assert_github_result src, src + assert_parsing_result src, src end describe 'github markdown' do it 'removes markdown links or nested tags inside HTML comments' do @@ -116,18 +93,18 @@ 11<!-- a href=&quot;#&quot;c4/a -->12</p> <p>Three</p> HTML - assert_github_result md, html + assert_parsing_result md, html end it 'generates apostrophes from single quotes in plain text' do md = "That's it" html = "<p>That’s it</p>" - assert_github_result(md, html) + assert_parsing_result(md, html) end it 'generates apostrophes from single quotes in callout|warning|note blocks' do md = <<-MARKDOWN > warning @@ -136,43 +113,17 @@ html = <<-HTML <div class="warning"> <p>That’s it</p> </div> HTML - assert_github_result(md, html) + assert_parsing_result(md, html) end it 'supports code blocks, respecting indentation and adding a custom class attribute' do md = <<-MARKDOWN Paragraph - :::term - $ command - - indented - < tag1 - > tag2 - -Another paragraph -MARKDOWN - - html = <<-HTML -<p>Paragraph</p> - -<pre><code class="term">$ command - - indented -&lt; tag1 -&gt; tag2</code></pre> - -<p>Another paragraph</p> -HTML - assert_maruku_result md, html - - md = <<-MARKDOWN -Paragraph - ```term $ command indented < tag1 @@ -192,14 +143,14 @@ &gt; tag2 </code></pre> <p>Another paragraph</p> HTML - assert_github_result md, html + assert_parsing_result md, html end - it 'github markdown supports regular block quotes without callout|warning|note' do + it 'supports regular block quotes without callout|warning|note' do md = <<-MARKDOWN Testing > not a callout > **strong** @@ -218,11 +169,11 @@ </blockquote> <p>And that’s it.</p> HTML - assert_github_result(md, html) + assert_parsing_result(md, html) md = <<-MARKDOWN Testing > calloutnonono @@ -242,14 +193,14 @@ </blockquote> <p>And that’s it.</p> HTML - assert_github_result(md, html) + assert_parsing_result(md, html) end - it 'github markdown supports "> callout" and ">callout" and parses inner markdown' do + it 'supports "> callout" and ">callout" and parses inner markdown' do mds = [] mds << <<-MARKDOWN Testing > callout @@ -279,15 +230,15 @@ <p>And that’s it.</p> HTML mds.each do |md| - assert_github_result(md, html) + assert_parsing_result(md, html) end end - it 'github markdown supports "> callout" and ">callout", parses inner markdown and allows paragraphs' do + it 'supports "> callout" and ">callout", parses inner markdown and allows paragraphs' do mds = [] mds << <<-MARKDOWN Testing > callout @@ -327,16 +278,16 @@ <p>And that’s it.</p> HTML mds.each do |md| - assert_github_result(md, html) + assert_parsing_result(md, html) end end end - it 'github markdown generates separate special blocks from blockquotes separated by empty lines' do + it 'generates separate special blocks from blockquotes separated by empty lines' do md = <<-MARKDOWN > warning > foo > note @@ -353,27 +304,29 @@ <div class="note"> <p>bar</p> </div> HTML - assert_github_result md, html + assert_parsing_result md, html end - it 'github markdown supports tables' do + it 'supports tables' do md = <<-MARKDOWN | A | B | | --- | --- | | 1 | 2 | | 3 | 4 | MARKDOWN html = <<-HTML <table> -<thead><tr> +<thead> +<tr> <th>A</th> <th>B</th> -</tr></thead> +</tr> +</thead> <tbody> <tr> <td>1</td> <td>2</td> </tr> @@ -383,119 +336,89 @@ </tr> </tbody> </table> HTML - assert_github_result md, html + assert_parsing_result md, html end - it "does emdashes both in all flavours" do + it "does emdashes" do md = "foo -- bar" html = '<p>foo – bar</p>' - assert_all_flavours_result(md, html) + assert_parsing_result md, html end it 'converts relative links with missing initial slashes to article links' do ['foo', 'foo/bar', 'foo#bar', '123'].each do |href| md = "[link](#{href})" html = "<p><a href=\"/articles/#{href}\">link</a></p>" - assert_maruku_result md, html - assert_github_result md, html + assert_parsing_result md, html end end it 'converts "articles/foo relative links with missing initial slashes to article links' do md = '[link](articles/foo)' html = '<p><a href="/articles/foo">link</a></p>' - assert_maruku_result md, html - assert_github_result md, html + assert_parsing_result md, html md = '[link](articles/foo#bar)' html = '<p><a href="/articles/foo#bar">link</a></p>' - assert_maruku_result md, html - assert_github_result md, html + assert_parsing_result md, html end it 'does not alter relative links with initial slashes nor absolute links nor anchor links to the same doc' do ['http://foo.com', 'https://foo.com', '/foo', '/foo/bar', '/foo#bar', '#foo', '/123', 'mailto:foo@foobar.com'].each do |href| md = "[link](#{href})" html = "<p><a href=\"#{href}\">link</a></p>" - assert_maruku_result md, html - assert_github_result md, html + assert_parsing_result md, html end end it 'does not add href attribute to links where it does not exist' do md = '<a name="heh"></a>' html = '<p><a name="heh"></a></p>' - assert_maruku_result md, html - assert_github_result md, html + assert_parsing_result md, html end it 'generates separate blockquotes from blockquotes separated by empty lines' do md = <<-MARKDOWN > foo > bar MARKDOWN - html_maruku = <<-HTML + html = <<-HTML <blockquote> <p>foo</p> </blockquote> -<p class="devcenter-parser-special-block-separator" style="display:none"> </p> -<blockquote> -<p>bar</p> -</blockquote> - HTML - assert_maruku_result md, html_maruku - - html_github = <<-HTML -<blockquote> -<p>foo</p> -</blockquote> - <p class="devcenter-parser-special-block-separator" style="display:none"> </p> <blockquote> <p>bar</p> </blockquote> HTML - assert_github_result md, html_github + assert_parsing_result md, html end end # helpers - def assert_all_flavours_result(md, expected) - [:github, :maruku].each { |flavour| assert_parsing_result(md, flavour, expected) } + def assert_parsing_result(md, expected) + result = DevcenterParser.to_html(md) + assert_equal expected.strip, result.strip, "Failed when parsing\n#{md}\n.\n\nExpected:\n#{expected}\n\nActual result:\n#{result}\n\n" end - def assert_maruku_result(md, expected) - assert_parsing_result md, :maruku, expected + def assert_parsing_unsanitized_result(md, expected) + result = DevcenterParser.to_unsanitized_html(md) + assert_equal expected.strip, result.strip, "Failed when parsing on unsanitized mode\n#{md}\n.\n\nExpected:\n#{expected}\n\nActual result:\n#{result}\n\n" end - def assert_github_result(md, expected) - assert_parsing_result md, :github, expected - end - - def assert_parsing_result(md, flavour, expected) - result = DevcenterParser.to_html(md, flavour) - assert_equal expected.strip, result.strip, "Failed when parsing\n#{md}\nwith the #{flavour} flavour.\n\nExpected:\n#{expected}\n\nActual result:\n#{result}\n\n" - end - - def assert_parsing_unsanitized_result(md, flavour, expected) - result = DevcenterParser.to_unsanitized_html(md, flavour) - assert_equal expected.strip, result.strip, "Failed when parsing on unsanitized mode\n#{md}\nwith the #{flavour} flavour.\n\nExpected:\n#{expected}\n\nActual result:\n#{result}\n\n" - end - def assert_header_id(md, header, id) - assert DevcenterParser.to_html(md, :github).include?("<#{header} id=\"#{id}\">"), "GitHub does not generate a #{header} with id #{id}" - assert DevcenterParser.to_html(md, :maruku).include?("<#{header} id=\"#{id}\">"), "Maruku does not generate a #{header} with id #{id}" + assert DevcenterParser.to_html(md).include?("<#{header} id=\"#{id}\">"), "GitHub does not generate a #{header} with id #{id}" end end