Skip to content

Commit

Permalink
TDD: write test of escape_html renderer option
Browse files Browse the repository at this point in the history
  • Loading branch information
chitsaou authored and vmg committed Dec 13, 2011
1 parent bdf09d4 commit a87389b
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions test/redcarpet_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -60,13 +60,36 @@ def setup
:no_images => Redcarpet::Render::HTML.new(:no_images => true),
:no_links => Redcarpet::Render::HTML.new(:no_links => true),
:safe_links => Redcarpet::Render::HTML.new(:safe_links_only => true),
:escape_html => Redcarpet::Render::HTML.new(:escape_html => true),
}
end

def render_with(rndr, text)
Redcarpet::Markdown.new(rndr).render(text)
end

# Hint: overrides filter_html, no_images and no_links
def test_that_escape_html_works
source = <<EOS
Through <em>NO</em> <script>DOUBLE NO</script>
<script>BAD</script>
<img src="/favicon.ico" />
EOS
expected = <<EOE
<p>Through &lt;em&gt;NO&lt;/em&gt; &lt;script&gt;DOUBLE NO&lt;/script&gt;</p>
<p>&lt;script&gt;BAD&lt;/script&gt;</p>
<p>&lt;img src=&quot;/favicon.ico&quot; /&gt;
EOE

markdown = render_with(@rndr[:escape_html], source)
html_equal expected, markdown
end

def test_that_filter_html_works
markdown = render_with(@rndr[:no_html], 'Through <em>NO</em> <script>DOUBLE NO</script>')
html_equal "<p>Through NO DOUBLE NO</p>", markdown
Expand Down

0 comments on commit a87389b

Please sign in to comment.