# coding: UTF-8 require 'test_helper' class MarkdownTest < Redcarpet::TestCase def setup @markdown = Redcarpet::Markdown.new(Redcarpet::Render::HTML) end def render_with(flags, text) Redcarpet::Markdown.new(Redcarpet::Render::HTML, flags).render(text) end def test_that_simple_one_liner_goes_to_html assert_respond_to @markdown, :render assert_equal "
Hello World.
\n", @markdown.render("Hello World.") end def test_that_inline_markdown_goes_to_html markdown = @markdown.render('_Hello World_!') assert_equal "Hello World!
\n", markdown end def test_that_inline_markdown_starts_and_ends_correctly markdown = render_with({:no_intra_emphasis => true}, '_start _ foo_bar bar_baz _ end_ *italic* **bold** _blah_') assert_equal "start _ foo_bar bar_baz _ end italic bold blah
\n", markdown markdown = @markdown.render("Run 'rake radiant:extensions:rbac_base:migrate'") assert_equal "Run 'rake radiant:extensions:rbac_base:migrate'
\n", markdown end def test_that_urls_are_not_doubly_escaped markdown = @markdown.render('[Page 2](/search?query=Markdown+Test&page=2)') assert_equal "\n", markdown end def test_simple_inline_html #markdown = Markdown.new("before\n\nbefore
\n\nafter
\n", markdown end def test_that_html_blocks_do_not_require_their_own_end_tag_line markdown = @markdown.render("Para 1\n\nHTML block\n
Para 1
\n\nHTML block\n
Para 2 Link
\n", markdown end # This isn't in the spec but is Markdown.pl behavior. def test_block_quotes_preceded_by_spaces markdown = @markdown.render( "A wise man once said:\n\n" + " > Isn't it wonderful just to be alive.\n" ) assert_equal "A wise man once said:
\n\n" + "\n\n", markdown end def test_para_before_block_html_should_not_wrap_in_p_tag markdown = render_with({:lax_spacing => true}, "Things to watch out for\n" + "Isn't it wonderful just to be alive.
\n
Things to watch out for
\n\n" + "This paragraph is not part of the list.
HTML assert_equal expected, @markdown.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
\n", @markdown.render(text) end def test_that_intra_emphasis_works rd = render_with({}, "foo_bar_baz") assert_equal "foobarbaz
\n", rd rd = render_with({:no_intra_emphasis => true},"foo_bar_baz") assert_equal "foo_bar_baz
\n", rd end def test_that_autolink_flag_works rd = render_with({:autolink => true}, "http://github.com/rtomayko/rdiscount") assert_equal "http://github.com/rtomayko/rdiscount
\n", rd end def test_that_tags_can_have_dashes_and_underscores rd = @markdown.render("foofoo
This is a code block\nThis is a link [[1]] inside\n
\n",
markdown
end
def test_whitespace_after_urls
rd = render_with({:autolink => true}, "Japan: http://www.abc.net.au/news/events/japan-quake-2011/beforeafter.htm (yes, japan)")
exp = %{Japan: http://www.abc.net.au/news/events/japan-quake-2011/beforeafter.htm (yes, japan)
\n} assert_equal exp, rd end def test_memory_leak_when_parsing_char_links @markdown.render(<<-leaks) 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 "-
\n", @markdown.render("-") assert_equal "=
\n", @markdown.render("=") end def test_that_tables_flag_works text = <