test/devcenter-parser_test.rb in devcenter-parser-1.3.9 vs test/devcenter-parser_test.rb in devcenter-parser-1.4.0

- old
+ new

@@ -3,19 +3,19 @@ require_relative '../lib/devcenter-parser' 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, '' 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, :maruku, '<script>alert("hi")</script>' assert_parsing_unsanitized_result md, :github, '<script>alert("hi")</script>' end end @@ -31,46 +31,17 @@ assert_raises DevcenterParser::InvalidMarkdownError do DevcenterParser.to_html(md, :maruku) end end - it 'respects existing ids' do - md = '<strong id="foo">clean</strong>' - html = '<p><strong id="foo">clean</strong></p>' - assert_maruku_result md, html - assert_github_result md, html - 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 end - it 'includes ids in subheaders' do - md = <<-MARKDOWN -## Foo Bar Header 123 - -Foo bar content - MARKDOWN - assert DevcenterParser.to_html(md, :github).include?('<h2 id="foo-bar-header-123">Foo Bar Header 123</h2>') - assert DevcenterParser.to_html(md, :maruku).include?('<h2 id="foo-bar-header-123">Foo Bar Header 123</h2>') - end - - it 'generates ids replacing inner non-alphanum chars with dashes' do - ['Foo Bar', 'Foo-Bar', 'Foo#bar', 'Foo##Bar', 'Foo##Bar', '-$Foo##Bar$-'].each do |title| - md = <<-MARKDOWN -## #{title} - -Foo bar content -MARKDOWN - assert DevcenterParser.to_html(md, :github).include?("<h2 id=\"foo-bar\">#{title}</h2>"), "GitHub with title #{title}: " + DevcenterParser.to_html(md, :github) - assert DevcenterParser.to_html(md, :maruku).include?("<h2 id=\"foo-bar\">#{title}</h2>"), "Maruku: " + DevcenterParser.to_html(md, :maruku) - end - end - describe 'github markdown' do it 'generates apostrophes from single quotes in plain text' do md = "That's it" html = "<p>That’s it</p>" @@ -239,11 +210,11 @@ mds << <<-MARKDOWN Testing > callout > **strong** -> more callout +> more callout > normal And that's it. MARKDOWN @@ -251,11 +222,11 @@ mds << <<-MARKDOWN Testing >callout >**strong** ->more callout +>more callout >normal And that's it. MARKDOWN @@ -310,11 +281,11 @@ it 'github markdown supports tables' do md = <<-MARKDOWN | A | B | | --- | --- | | 1 | 2 | -| 3 | 4 | +| 3 | 4 | MARKDOWN html = <<-HTML <table> <thead><tr> @@ -428,6 +399,11 @@ 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 -end \ No newline at end of file + 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}" + end + +end