# coding: UTF-8 require 'test_helper' class MarkdownTest < Redcarpet::TestCase def setup @renderer = Redcarpet::Render::HTML end def test_that_simple_one_liner_goes_to_html assert_equal "
Hello World.
", render("Hello World.") end def test_that_inline_markdown_goes_to_html assert_equal "Hello World!
", render('_Hello World_!') end def test_that_inline_markdown_starts_and_ends_correctly output = render('_start _ foo_bar bar_baz _ end_ *italic* **bold** _blah_', with: [:no_intra_emphasis]) expected = "start _ foo_bar bar_baz _ end italic bold blah
" assert_equal expected, output output = render("Run 'rake radiant:extensions:rbac_base:migrate'") expected = "Run 'rake radiant:extensions:rbac_base:migrate'
" assert_equal expected, output end def test_that_urls_are_not_doubly_escaped output = render('[Page 2](/search?query=Markdown+Test&page=2)') assert_equal "", output end def test_simple_inline_html output = render("before\n\nbefore
\n\nafter
" assert_equal expected, output end def test_that_html_blocks_do_not_require_their_own_end_tag_line output = render("Para 1\n\nHTML block\n
Para 1
\n\nHTML block\n
Para 2 Link
" assert_equal expected, output end # This isn't in the spec but is Markdown.pl behavior. def test_block_quotes_preceded_by_spaces output = render <<-Markdown.strip_heredoc A wise man once said: > Isn't it wonderful just to be alive. Markdown expected = <<-HTML.chomp.strip_heredocA wise man once said:
HTML assert_equal expected, output end def test_para_before_block_html_should_not_wrap_in_p_tag output = render("Things to watch out for\nIsn't it wonderful just to be alive.
Things to watch out for
\n\nThis paragraph is not part of the list.
HTML assert_equal expected, render(text) end # http://github.com/rtomayko/rdiscount/issues/#issue/13 def test_headings_with_trailing_space text = "The Ant-Sugar Tales \n" + "=================== \n\n" + "By Candice Yellowflower \n" assert_equal "By Candice Yellowflower
", render(text) end def test_that_intra_emphasis_works assert_equal "foobarbaz
", render("foo_bar_baz") assert_equal "foo_bar_baz
", render("foo_bar_baz", with: [:no_intra_emphasis]) end def test_that_autolink_flag_works output = render("http://github.com/rtomayko/rdiscount", with: [:autolink]) expected = "http://github.com/rtomayko/rdiscount
" assert_equal expected, output end def test_that_tags_can_have_dashes_and_underscores output = render("foofoo
This is a code block\nThis is a link [[1]] inside\n
"
assert_equal expected, output
end
def test_whitespace_after_urls
output = render("Japan: http://www.abc.net.au/news/events/japan-quake-2011/beforeafter.htm (yes, japan)", with: [:autolink])
expected = %(Japan: http://www.abc.net.au/news/events/japan-quake-2011/beforeafter.htm (yes, japan)
) assert_equal expected, output end def test_memory_leak_when_parsing_char_links render(<<-leaks.strip_heredoc) 2. Identify the wild-type cluster and determine all clusters containing or contained by it: wildtype <- wildtype.cluster(h) wildtype.mask <- logical(nclust) wildtype.mask[c(contains(h, wildtype), wildtype, contained.by(h, wildtype))] <- TRUE This could be more elegant. leaks end def test_infinite_loop_in_header assert_equal "-
", render("-") assert_equal "=
", render("=") end def test_that_tables_flag_works text = <<-Markdown.strip_heredoc aaa | bbbb -----|------ hello|sailor Markdown assert render(text) !~ /