# encoding: utf-8 rootdir = File.dirname(File.dirname(__FILE__)) $LOAD_PATH.unshift "#{rootdir}/lib" require 'test/unit' require 'rdiscount' class RDiscountTest < Test::Unit::TestCase def test_that_version_looks_valid if not /^[0-9]+\.[0-9]+\.[0-9]+(\.[0-9]+)?$/ =~ RDiscount::VERSION assert false, 'Expected RDiscount::VERSION to be a 3 or 4 component version string but found ' + RDiscount::VERSION.to_s end end def test_that_discount_does_not_blow_up_with_weird_formatting_case text = (<<-TEXT).gsub(/^ {4}/, '').rstrip 1. some text 1. TEXT RDiscount.new(text).to_html end def test_that_smart_converts_double_quotes_to_curly_quotes rd = RDiscount.new(%("Quoted text"), :smart) assert_equal %(

“Quoted text”

\n), rd.to_html end def test_that_smart_converts_double_quotes_to_curly_quotes_before_a_heading rd = RDiscount.new(%("Quoted text"\n\n# Heading), :smart) assert_equal %(

“Quoted text”

\n\n

Heading

\n), rd.to_html end def test_that_smart_converts_double_quotes_to_curly_quotes_after_a_heading rd = RDiscount.new(%(# Heading\n\n"Quoted text"), :smart) assert_equal %(

Heading

\n\n

“Quoted text”

\n), rd.to_html end def test_that_smart_gives_ve_suffix_a_rsquo rd = RDiscount.new("I've been meaning to tell you ..", :smart) assert_equal "

I’ve been meaning to tell you ..

\n", rd.to_html end def test_that_smart_gives_m_suffix_a_rsquo rd = RDiscount.new("I'm not kidding", :smart) assert_equal "

I’m not kidding

\n", rd.to_html end def test_that_smart_gives_d_suffix_a_rsquo rd = RDiscount.new("what'd you say?", :smart) assert_equal "

what’d you say?

\n", rd.to_html end def test_that_generate_toc_sets_toc_ids rd = RDiscount.new("# Level 1\n\n## Level 2", :generate_toc) assert rd.generate_toc assert_equal %(\n

Level 1

\n\n\n

Level 2

\n), rd.to_html end def test_should_get_the_generated_toc rd = RDiscount.new("# Level 1\n\n## Level 2", :generate_toc) exp = %() assert_equal exp, rd.toc_content.strip end def test_toc_should_escape_apostropes rd = RDiscount.new("# A'B\n\n## C", :generate_toc) exp = %() assert_equal exp, rd.toc_content.strip end def test_toc_should_escape_question_marks rd = RDiscount.new("# A?B\n\n## C", :generate_toc) exp = %() assert_equal exp, rd.toc_content.strip end if "".respond_to?(:encoding) def test_should_return_string_in_same_encoding_as_input input = "Yogācāra" output = RDiscount.new(input).to_html assert_equal input.encoding.name, output.encoding.name end end def test_that_no_image_flag_works rd = RDiscount.new(%(![dust mite](http://dust.mite/image.png) ), :no_image) assert rd.to_html !~ /links), :no_links) assert rd.to_html !~ /foobarbaz

\n", rd.to_html end def test_that_autolink_flag_works rd = RDiscount.new("http://github.com/davidfstr/rdiscount", :autolink) assert_equal "

http://github.com/davidfstr/rdiscount

\n", rd.to_html end def test_that_safelink_flag_works rd = RDiscount.new("[IRC](irc://chat.freenode.org/#freenode)", :safelink) assert_equal "

[IRC](irc://chat.freenode.org/#freenode)

\n", rd.to_html end def test_that_no_pseudo_protocols_flag_works rd = RDiscount.new("[foo](id:bar)", :no_pseudo_protocols) assert_equal "

[foo](id:bar)

\n", rd.to_html end def test_that_no_superscript_flag_works rd = RDiscount.new("A^B", :no_superscript) assert_equal "

A^B

\n", rd.to_html rd = RDiscount.new("A^B") assert_equal "

AB

\n", rd.to_html end def test_that_no_strikethrough_flag_works rd = RDiscount.new("~~A~~", :no_strikethrough) assert_equal "

~~A~~

\n", rd.to_html rd = RDiscount.new("~~A~~") assert_equal "

A

\n", rd.to_html end def test_that_tags_can_have_dashes_and_underscores if RDiscount::VERSION.start_with? "2.0.7" # Skip test for 2.0.7.x series due to upstream behavioral change in # Discount 2.0.7. This test can be fixed in Discount 2.1.5 using the # WITH_GITHUB_TAGS compile-time flag. return end rd = RDiscount.new("foo bar and baz") assert_equal "

foo bar and baz

\n", rd.to_html end def test_that_footnotes_flag_works rd = RDiscount.new(<1') end def test_that_footnotes_in_span_works rd = RDiscount.new(<1') end def test_that_unicode_urls_encoded_correctly rd = RDiscount.new("[Test](http://example.com/ß)") assert_equal "

Test

\n", rd.to_html end def test_that_dashes_encoded_correctly rd = RDiscount.new("A--B", :smart) assert_equal "

A–B

\n", rd.to_html rd = RDiscount.new("A---B", :smart) assert_equal "

A—B

\n", rd.to_html end def test_that_superscripts_can_be_escaped rd = RDiscount.new("A\\^B") assert_equal "

A^B

\n", rd.to_html rd = RDiscount.new("A^B") assert_equal "

AB

\n", rd.to_html end def test_that_style_tag_is_not_filtered_by_default rd = RDiscount.new("Hello") assert_equal "

Hello

\n", rd.to_html end def test_that_tables_can_have_leading_and_trailing_pipes rd = RDiscount.new(<\n\n\n A \n B \n\n\n\n\n C \n D \n\n\n\n\n", rd.to_html end def test_that_gfm_code_blocks_work rd = RDiscount.new(<line 1\n\nline 2\n\n", rd.to_html end def test_that_gfm_code_blocks_work_with_language rd = RDiscount.new(<line 1\n\nline 2\n\n", rd.to_html end def test_that_pandoc_code_blocks_work rd = RDiscount.new(<line 1\n\nline 2\n\n", rd.to_html end def test_that_discount_definition_lists_work rd = RDiscount.new(<
tag1
tag2
data.
EOS end def test_that_extra_definition_lists_work rd = RDiscount.new(<
tag1
data
EOS end def test_that_emphasis_beside_international_characters_detected rd = RDiscount.new(%(*foo ä bar*)) assert_equal %(

foo ä bar

\n), rd.to_html rd = RDiscount.new(%(*ä foobar*)) assert_equal %(

ä foobar

\n), rd.to_html rd = RDiscount.new(%(*foobar ä*)) assert_equal %(

foobar ä

\n), rd.to_html end end