chaptastic-rdiscount 1.4.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,119 @@
1
+ rootdir = File.dirname(File.dirname(__FILE__))
2
+ $LOAD_PATH.unshift "#{rootdir}/lib"
3
+
4
+ require 'test/unit'
5
+ require 'markdown'
6
+
7
+ MARKDOWN_TEST_DIR = "#{rootdir}/test/MarkdownTest_1.0.3"
8
+
9
+ class MarkdownTest < Test::Unit::TestCase
10
+
11
+ def test_that_extension_methods_are_present_on_markdown_class
12
+ assert Markdown.instance_methods.map{|m| m.to_s }.include?('to_html'),
13
+ "Markdown class should respond to #to_html"
14
+ end
15
+
16
+ def test_that_simple_one_liner_goes_to_html
17
+ markdown = Markdown.new('Hello World.')
18
+ assert_respond_to markdown, :to_html
19
+ assert_equal "<p>Hello World.</p>", markdown.to_html.strip
20
+ end
21
+
22
+ def test_that_inline_markdown_goes_to_html
23
+ markdown = Markdown.new('_Hello World_!')
24
+ assert_equal "<p><em>Hello World</em>!</p>", markdown.to_html.strip
25
+ end
26
+
27
+ def test_that_inline_markdown_starts_and_ends_correctly
28
+ markdown = Markdown.new('_start _ foo_bar bar_baz _ end_ *italic* **bold** <a>_blah_</a>')
29
+ assert_respond_to markdown, :to_html
30
+ assert_equal "<p><em>start _ foo_bar bar_baz _ end</em> <em>italic</em> <strong>bold</strong> <a><em>blah</em></a></p>", markdown.to_html.strip
31
+
32
+ markdown = Markdown.new("Run 'rake radiant:extensions:rbac_base:migrate'")
33
+ assert_equal "<p>Run 'rake radiant:extensions:rbac_base:migrate'</p>", markdown.to_html.strip
34
+ end
35
+
36
+ def test_that_filter_html_works
37
+ markdown = Markdown.new('Through <em>NO</em> <script>DOUBLE NO</script>', :filter_html)
38
+ assert_equal "<p>Through &lt;em>NO&lt;/em> &lt;script>DOUBLE NO&lt;/script></p>", markdown.to_html.strip
39
+ end
40
+
41
+ def test_that_bluecloth_restrictions_are_supported
42
+ markdown = Markdown.new('Hello World.')
43
+ [:filter_html, :filter_styles].each do |restriction|
44
+ assert_respond_to markdown, restriction
45
+ assert_respond_to markdown, "#{restriction}="
46
+ end
47
+ assert_not_equal true, markdown.filter_html
48
+ assert_not_equal true, markdown.filter_styles
49
+
50
+ markdown = Markdown.new('Hello World.', :filter_html, :filter_styles)
51
+ assert_equal true, markdown.filter_html
52
+ assert_equal true, markdown.filter_styles
53
+ end
54
+
55
+ def test_that_redcloth_attributes_are_supported
56
+ markdown = Markdown.new('Hello World.')
57
+ assert_respond_to markdown, :fold_lines
58
+ assert_respond_to markdown, :fold_lines=
59
+ assert_not_equal true, markdown.fold_lines
60
+
61
+ markdown = Markdown.new('Hello World.', :fold_lines)
62
+ assert_equal true, markdown.fold_lines
63
+ end
64
+
65
+ def test_that_redcloth_to_html_with_single_arg_is_supported
66
+ markdown = Markdown.new('Hello World.')
67
+ assert_nothing_raised(ArgumentError) { markdown.to_html(true) }
68
+ end
69
+
70
+ def test_that_smart_converts_single_quotes_in_words_that_end_in_re
71
+ markdown = Markdown.new("They're not for sale.", :smart)
72
+ assert_equal "<p>They&rsquo;re not for sale.</p>\n", markdown.to_html
73
+ end
74
+
75
+ def test_that_smart_converts_single_quotes_in_words_that_end_in_ll
76
+ markdown = Markdown.new("Well that'll be the day", :smart)
77
+ assert_equal "<p>Well that&rsquo;ll be the day</p>\n", markdown.to_html
78
+ end
79
+
80
+ def test_that_urls_are_not_doubly_escaped
81
+ markdown = Markdown.new('[Page 2](/search?query=Markdown+Test&page=2)')
82
+ assert_equal "<p><a href=\"/search?query=Markdown+Test&amp;page=2\">Page 2</a></p>\n", markdown.to_html
83
+ end
84
+
85
+ def test_simple_inline_html
86
+ markdown = Markdown.new("before\n\n<div>\n foo\n</div>\nafter")
87
+ assert_equal "<p>before</p>\n\n<div>\n foo\n</div>\n\n\n<p>after</p>\n",
88
+ markdown.to_html
89
+ end
90
+
91
+ def test_that_html_blocks_do_not_require_their_own_end_tag_line
92
+ markdown = Markdown.new("Para 1\n\n<div><pre>HTML block\n</pre></div>\n\nPara 2 [Link](#anchor)")
93
+ assert_equal "<p>Para 1</p>\n\n<div><pre>HTML block\n</pre></div>\n\n\n<p>Para 2 <a href=\"#anchor\">Link</a></p>\n",
94
+ markdown.to_html
95
+ end
96
+
97
+ # Build tests for each file in the MarkdownTest test suite
98
+
99
+ Dir["#{MARKDOWN_TEST_DIR}/Tests/*.text"].each do |text_file|
100
+
101
+ basename = File.basename(text_file).sub(/\.text$/, '')
102
+ html_file = text_file.sub(/text$/, 'html')
103
+ method_name = basename.gsub(/[-,]/, '').gsub(/\s+/, '_').downcase
104
+
105
+ define_method "test_#{method_name}" do
106
+ markdown = Markdown.new(File.read(text_file))
107
+ actual_html = markdown.to_html
108
+ assert_not_nil actual_html
109
+ end
110
+
111
+ define_method "test_#{method_name}_with_smarty_enabled" do
112
+ markdown = Markdown.new(File.read(text_file), :smart)
113
+ actual_html = markdown.to_html
114
+ assert_not_nil actual_html
115
+ end
116
+
117
+ end
118
+
119
+ end
@@ -0,0 +1,43 @@
1
+ rootdir = File.dirname(File.dirname(__FILE__))
2
+ $LOAD_PATH.unshift "#{rootdir}/lib"
3
+
4
+ require 'test/unit'
5
+ require 'rdiscount'
6
+
7
+ class RDiscountTest < Test::Unit::TestCase
8
+ def test_that_discount_does_not_blow_up_with_weird_formatting_case
9
+ text = (<<-TEXT).gsub(/^ {4}/, '').rstrip
10
+ 1. some text
11
+
12
+ 1.
13
+ TEXT
14
+ RDiscount.new(text).to_html
15
+ end
16
+
17
+ def test_that_smart_converts_double_quotes_to_curly_quotes
18
+ rd = RDiscount.new(%("Quoted text"), :smart)
19
+ assert_equal %(<p>&ldquo;Quoted text&rdquo;</p>\n), rd.to_html
20
+ end
21
+
22
+ def test_that_smart_converts_double_quotes_to_curly_quotes_before_a_heading
23
+ rd = RDiscount.new(%("Quoted text"\n\n# Heading), :smart)
24
+ assert_equal %(<p>&ldquo;Quoted text&rdquo;</p>\n\n<h1>Heading</h1>\n), rd.to_html
25
+ end
26
+
27
+ def test_that_smart_converts_double_quotes_to_curly_quotes_after_a_heading
28
+ rd = RDiscount.new(%(# Heading\n\n"Quoted text"), :smart)
29
+ assert_equal %(<h1>Heading</h1>\n\n<p>&ldquo;Quoted text&rdquo;</p>\n), rd.to_html
30
+ end
31
+
32
+ def test_that_generate_toc_sets_toc_ids
33
+ rd = RDiscount.new("# Level 1\n\n## Level 2", :generate_toc)
34
+ assert rd.generate_toc
35
+ assert_equal %(<h1 id="Level+1\">Level 1</h1>\n\n<h2 id="Level+2\">Level 2</h2>\n), rd.to_html
36
+ end
37
+
38
+ def test_should_get_the_generated_toc
39
+ rd = RDiscount.new("# Level 1\n\n## Level 2", :generate_toc)
40
+ exp = %(<ul>\n <li><a href="#Level+1">Level 1</a>\n <ul>\n <li><a href="#Level+2">Level 2</a> </li>\n </ul>\n </li>\n </ul>)
41
+ assert_equal exp, rd.toc_content.strip
42
+ end
43
+ end
metadata ADDED
@@ -0,0 +1,83 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: chaptastic-rdiscount
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.4.1
5
+ platform: ruby
6
+ authors:
7
+ - Ryan Tomayko
8
+ - Andrew White
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+
13
+ date: 2009-06-23 00:00:00 -07:00
14
+ default_executable:
15
+ dependencies: []
16
+
17
+ description:
18
+ email: r@tomayko.com
19
+ executables:
20
+ - rdiscount
21
+ extensions:
22
+ - ext/extconf.rb
23
+ extra_rdoc_files:
24
+ - COPYING
25
+ files:
26
+ - COPYING
27
+ - README.markdown
28
+ - Rakefile
29
+ - bin/rdiscount
30
+ - ext/Csio.c
31
+ - ext/amalloc.h
32
+ - ext/config.h
33
+ - ext/css.c
34
+ - ext/cstring.h
35
+ - ext/docheader.c
36
+ - ext/dumptree.c
37
+ - ext/extconf.rb
38
+ - ext/generate.c
39
+ - ext/markdown.c
40
+ - ext/markdown.h
41
+ - ext/mkdio.c
42
+ - ext/mkdio.h
43
+ - ext/rdiscount.c
44
+ - ext/resource.c
45
+ - ext/toc.c
46
+ - ext/xml.c
47
+ - ext/xmlpage.c
48
+ - lib/markdown.rb
49
+ - lib/rdiscount.rb
50
+ - rdiscount.gemspec
51
+ - test/benchmark.rb
52
+ - test/benchmark.txt
53
+ - test/markdown_test.rb
54
+ - test/rdiscount_test.rb
55
+ has_rdoc: true
56
+ homepage: http://github.com/rtomayko/rdiscount
57
+ post_install_message:
58
+ rdoc_options: []
59
+
60
+ require_paths:
61
+ - lib
62
+ required_ruby_version: !ruby/object:Gem::Requirement
63
+ requirements:
64
+ - - ">="
65
+ - !ruby/object:Gem::Version
66
+ version: "0"
67
+ version:
68
+ required_rubygems_version: !ruby/object:Gem::Requirement
69
+ requirements:
70
+ - - ">="
71
+ - !ruby/object:Gem::Version
72
+ version: "0"
73
+ version:
74
+ requirements: []
75
+
76
+ rubyforge_project: wink
77
+ rubygems_version: 1.2.0
78
+ signing_key:
79
+ specification_version: 2
80
+ summary: Fast Implementation of Gruber's Markdown in C
81
+ test_files:
82
+ - test/markdown_test.rb
83
+ - test/rdiscount_test.rb