rdoc 3.12.2 → 4.0.0.preview2

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of rdoc might be problematic. Click here for more details.

Files changed (200) hide show
  1. checksums.yaml +6 -6
  2. checksums.yaml.gz.sig +0 -0
  3. data.tar.gz.sig +0 -0
  4. data/.autotest +3 -2
  5. data/DEVELOPERS.rdoc +53 -0
  6. data/History.rdoc +159 -25
  7. data/LEGAL.rdoc +12 -0
  8. data/Manifest.txt +56 -3
  9. data/README.rdoc +87 -19
  10. data/Rakefile +11 -2
  11. data/TODO.rdoc +20 -13
  12. data/bin/rdoc +4 -0
  13. data/lib/gauntlet_rdoc.rb +1 -1
  14. data/lib/rdoc.rb +32 -71
  15. data/lib/rdoc/any_method.rb +75 -21
  16. data/lib/rdoc/attr.rb +49 -10
  17. data/lib/rdoc/class_module.rb +182 -32
  18. data/lib/rdoc/code_object.rb +54 -12
  19. data/lib/rdoc/comment.rb +8 -1
  20. data/lib/rdoc/constant.rb +100 -6
  21. data/lib/rdoc/context.rb +93 -41
  22. data/lib/rdoc/context/section.rb +143 -28
  23. data/lib/rdoc/cross_reference.rb +58 -50
  24. data/lib/rdoc/encoding.rb +34 -29
  25. data/lib/rdoc/erb_partial.rb +18 -0
  26. data/lib/rdoc/extend.rb +117 -0
  27. data/lib/rdoc/generator.rb +11 -6
  28. data/lib/rdoc/generator/darkfish.rb +250 -62
  29. data/lib/rdoc/generator/json_index.rb +20 -12
  30. data/lib/rdoc/generator/markup.rb +10 -12
  31. data/lib/rdoc/generator/ri.rb +7 -60
  32. data/lib/rdoc/generator/template/darkfish/_head.rhtml +7 -7
  33. data/lib/rdoc/generator/template/darkfish/_sidebar_extends.rhtml +16 -0
  34. data/lib/rdoc/generator/template/darkfish/_sidebar_in_files.rhtml +1 -1
  35. data/lib/rdoc/generator/template/darkfish/_sidebar_installed.rhtml +14 -0
  36. data/lib/rdoc/generator/template/darkfish/_sidebar_methods.rhtml +1 -1
  37. data/lib/rdoc/generator/template/darkfish/_sidebar_table_of_contents.rhtml +13 -0
  38. data/lib/rdoc/generator/template/darkfish/class.rhtml +15 -1
  39. data/lib/rdoc/generator/template/darkfish/images/arrow_up.png +0 -0
  40. data/lib/rdoc/generator/template/darkfish/index.rhtml +3 -3
  41. data/lib/rdoc/generator/template/darkfish/js/darkfish.js +7 -9
  42. data/lib/rdoc/generator/template/darkfish/page.rhtml +2 -0
  43. data/lib/rdoc/generator/template/darkfish/rdoc.css +31 -0
  44. data/lib/rdoc/generator/template/darkfish/servlet_not_found.rhtml +18 -0
  45. data/lib/rdoc/generator/template/darkfish/servlet_root.rhtml +37 -0
  46. data/lib/rdoc/generator/template/darkfish/table_of_contents.rhtml +3 -3
  47. data/lib/rdoc/include.rb +12 -3
  48. data/lib/rdoc/markdown.kpeg +1186 -0
  49. data/lib/rdoc/markdown.rb +16336 -0
  50. data/lib/rdoc/markdown/entities.rb +2128 -0
  51. data/lib/rdoc/markdown/literals_1_8.kpeg +18 -0
  52. data/lib/rdoc/markdown/literals_1_8.rb +454 -0
  53. data/lib/rdoc/markdown/literals_1_9.kpeg +22 -0
  54. data/lib/rdoc/markdown/literals_1_9.rb +417 -0
  55. data/lib/rdoc/markup.rb +69 -10
  56. data/lib/rdoc/markup/attr_changer.rb +2 -5
  57. data/lib/rdoc/markup/attribute_manager.rb +23 -14
  58. data/lib/rdoc/markup/attributes.rb +70 -0
  59. data/lib/rdoc/markup/block_quote.rb +14 -0
  60. data/lib/rdoc/markup/document.rb +20 -4
  61. data/lib/rdoc/markup/formatter.rb +17 -6
  62. data/lib/rdoc/markup/formatter_test_case.rb +93 -24
  63. data/lib/rdoc/markup/hard_break.rb +31 -0
  64. data/lib/rdoc/markup/heading.rb +1 -1
  65. data/lib/rdoc/markup/indented_paragraph.rb +14 -0
  66. data/lib/rdoc/markup/list.rb +23 -4
  67. data/lib/rdoc/markup/list_item.rb +17 -4
  68. data/lib/rdoc/markup/paragraph.rb +14 -0
  69. data/lib/rdoc/markup/parser.rb +107 -60
  70. data/lib/rdoc/markup/raw.rb +4 -4
  71. data/lib/rdoc/markup/special.rb +3 -3
  72. data/lib/rdoc/markup/to_ansi.rb +7 -1
  73. data/lib/rdoc/markup/to_html.rb +42 -14
  74. data/lib/rdoc/markup/to_html_crossref.rb +10 -9
  75. data/lib/rdoc/markup/to_html_snippet.rb +20 -4
  76. data/lib/rdoc/markup/to_joined_paragraph.rb +68 -0
  77. data/lib/rdoc/markup/to_label.rb +20 -1
  78. data/lib/rdoc/markup/to_markdown.rb +134 -0
  79. data/lib/rdoc/markup/to_rdoc.rb +36 -5
  80. data/lib/rdoc/markup/to_table_of_contents.rb +6 -1
  81. data/lib/rdoc/markup/to_tt_only.rb +11 -2
  82. data/lib/rdoc/markup/verbatim.rb +19 -0
  83. data/lib/rdoc/method_attr.rb +33 -19
  84. data/lib/rdoc/normal_class.rb +26 -7
  85. data/lib/rdoc/normal_module.rb +10 -5
  86. data/lib/rdoc/options.rb +95 -21
  87. data/lib/rdoc/parser.rb +6 -2
  88. data/lib/rdoc/parser/c.rb +212 -97
  89. data/lib/rdoc/parser/markdown.rb +23 -0
  90. data/lib/rdoc/parser/ruby.rb +115 -35
  91. data/lib/rdoc/parser/ruby_tools.rb +8 -3
  92. data/lib/rdoc/rd.rb +8 -4
  93. data/lib/rdoc/rd/block_parser.rb +1 -1
  94. data/lib/rdoc/rd/block_parser.ry +1 -1
  95. data/lib/rdoc/rdoc.rb +45 -21
  96. data/lib/rdoc/ri/driver.rb +322 -76
  97. data/lib/rdoc/ri/paths.rb +90 -31
  98. data/lib/rdoc/ri/store.rb +2 -353
  99. data/lib/rdoc/ruby_lex.rb +5 -21
  100. data/lib/rdoc/ruby_token.rb +2 -3
  101. data/lib/rdoc/rubygems_hook.rb +21 -9
  102. data/lib/rdoc/servlet.rb +302 -0
  103. data/lib/rdoc/stats.rb +28 -20
  104. data/lib/rdoc/store.rb +881 -0
  105. data/lib/rdoc/task.rb +2 -1
  106. data/lib/rdoc/test_case.rb +103 -1
  107. data/lib/rdoc/text.rb +5 -4
  108. data/lib/rdoc/tom_doc.rb +17 -16
  109. data/lib/rdoc/top_level.rb +43 -285
  110. data/test/MarkdownTest_1.0.3/Amps and angle encoding.text +21 -0
  111. data/test/MarkdownTest_1.0.3/Auto links.text +13 -0
  112. data/test/MarkdownTest_1.0.3/Backslash escapes.text +120 -0
  113. data/test/MarkdownTest_1.0.3/Blockquotes with code blocks.text +11 -0
  114. data/test/MarkdownTest_1.0.3/Code Blocks.text +14 -0
  115. data/test/MarkdownTest_1.0.3/Code Spans.text +6 -0
  116. data/test/MarkdownTest_1.0.3/Hard-wrapped paragraphs with list-like lines.text +8 -0
  117. data/test/MarkdownTest_1.0.3/Horizontal rules.text +67 -0
  118. data/test/MarkdownTest_1.0.3/Inline HTML (Advanced).text +15 -0
  119. data/test/MarkdownTest_1.0.3/Inline HTML (Simple).text +69 -0
  120. data/test/MarkdownTest_1.0.3/Inline HTML comments.text +13 -0
  121. data/test/MarkdownTest_1.0.3/Links, inline style.text +12 -0
  122. data/test/MarkdownTest_1.0.3/Links, reference style.text +71 -0
  123. data/test/MarkdownTest_1.0.3/Links, shortcut references.text +20 -0
  124. data/test/MarkdownTest_1.0.3/Literal quotes in titles.text +7 -0
  125. data/test/MarkdownTest_1.0.3/Markdown Documentation - Basics.text +306 -0
  126. data/test/MarkdownTest_1.0.3/Markdown Documentation - Syntax.text +888 -0
  127. data/test/MarkdownTest_1.0.3/Nested blockquotes.text +5 -0
  128. data/test/MarkdownTest_1.0.3/Ordered and unordered lists.text +131 -0
  129. data/test/MarkdownTest_1.0.3/Strong and em together.text +7 -0
  130. data/test/MarkdownTest_1.0.3/Tabs.text +21 -0
  131. data/test/MarkdownTest_1.0.3/Tidyness.text +5 -0
  132. data/test/test_attribute_manager.rb +7 -4
  133. data/test/test_rdoc_any_method.rb +84 -13
  134. data/test/test_rdoc_attr.rb +59 -9
  135. data/test/test_rdoc_class_module.rb +670 -73
  136. data/test/test_rdoc_code_object.rb +21 -1
  137. data/test/test_rdoc_comment.rb +1 -1
  138. data/test/test_rdoc_constant.rb +132 -0
  139. data/test/test_rdoc_context.rb +84 -18
  140. data/test/test_rdoc_context_section.rb +99 -15
  141. data/test/test_rdoc_cross_reference.rb +1 -1
  142. data/test/test_rdoc_encoding.rb +17 -1
  143. data/test/test_rdoc_extend.rb +94 -0
  144. data/test/test_rdoc_generator_darkfish.rb +45 -19
  145. data/test/test_rdoc_generator_json_index.rb +27 -7
  146. data/test/test_rdoc_generator_markup.rb +3 -3
  147. data/test/test_rdoc_generator_ri.rb +11 -9
  148. data/test/test_rdoc_include.rb +12 -0
  149. data/test/test_rdoc_markdown.rb +977 -0
  150. data/test/test_rdoc_markdown_test.rb +1891 -0
  151. data/test/test_rdoc_markup.rb +1 -1
  152. data/test/test_rdoc_markup_attribute_manager.rb +2 -2
  153. data/test/test_rdoc_markup_attributes.rb +39 -0
  154. data/test/test_rdoc_markup_document.rb +16 -1
  155. data/test/test_rdoc_markup_formatter.rb +7 -4
  156. data/test/test_rdoc_markup_hard_break.rb +31 -0
  157. data/test/test_rdoc_markup_indented_paragraph.rb +14 -0
  158. data/test/test_rdoc_markup_paragraph.rb +15 -1
  159. data/test/test_rdoc_markup_parser.rb +152 -89
  160. data/test/test_rdoc_markup_to_ansi.rb +23 -2
  161. data/test/test_rdoc_markup_to_bs.rb +24 -0
  162. data/test/test_rdoc_markup_to_html.rb +50 -19
  163. data/test/test_rdoc_markup_to_html_crossref.rb +23 -5
  164. data/test/test_rdoc_markup_to_html_snippet.rb +49 -8
  165. data/test/test_rdoc_markup_to_joined_paragraph.rb +32 -0
  166. data/test/test_rdoc_markup_to_label.rb +63 -1
  167. data/test/test_rdoc_markup_to_markdown.rb +352 -0
  168. data/test/test_rdoc_markup_to_rdoc.rb +22 -2
  169. data/test/test_rdoc_markup_to_table_of_contents.rb +44 -39
  170. data/test/test_rdoc_markup_to_tt_only.rb +20 -0
  171. data/test/test_rdoc_markup_verbatim.rb +13 -0
  172. data/test/test_rdoc_method_attr.rb +5 -0
  173. data/test/test_rdoc_normal_class.rb +24 -5
  174. data/test/test_rdoc_normal_module.rb +1 -1
  175. data/test/test_rdoc_options.rb +21 -6
  176. data/test/test_rdoc_parser.rb +24 -0
  177. data/test/test_rdoc_parser_c.rb +151 -26
  178. data/test/test_rdoc_parser_markdown.rb +55 -0
  179. data/test/test_rdoc_parser_rd.rb +2 -2
  180. data/test/test_rdoc_parser_ruby.rb +468 -109
  181. data/test/test_rdoc_parser_simple.rb +2 -2
  182. data/test/test_rdoc_rd_block_parser.rb +0 -4
  183. data/test/test_rdoc_rdoc.rb +110 -22
  184. data/test/test_rdoc_ri_driver.rb +415 -80
  185. data/test/test_rdoc_ri_paths.rb +122 -13
  186. data/test/test_rdoc_ruby_lex.rb +5 -61
  187. data/test/test_rdoc_ruby_token.rb +19 -0
  188. data/test/test_rdoc_rubygems_hook.rb +64 -43
  189. data/test/test_rdoc_servlet.rb +429 -0
  190. data/test/test_rdoc_stats.rb +83 -24
  191. data/test/{test_rdoc_ri_store.rb → test_rdoc_store.rb} +395 -22
  192. data/test/test_rdoc_task.rb +2 -2
  193. data/test/test_rdoc_text.rb +37 -11
  194. data/test/test_rdoc_tom_doc.rb +59 -62
  195. data/test/test_rdoc_top_level.rb +71 -113
  196. data/test/xref_test_case.rb +7 -9
  197. metadata +122 -39
  198. metadata.gz.sig +0 -0
  199. data/CVE-2013-0256.rdoc +0 -49
  200. data/lib/rdoc/markup/attribute.rb +0 -51
@@ -130,7 +130,7 @@ class TestRDocCrossReference < XrefTestCase
130
130
  end
131
131
 
132
132
  def test_resolve_page
133
- page = RDoc::TopLevel.new 'README.txt'
133
+ page = @store.add_file 'README.txt'
134
134
  page.parser = RDoc::Parser::Simple
135
135
 
136
136
  assert_ref page, 'README'
@@ -53,7 +53,7 @@ class TestRDocEncoding < RDoc::TestCase
53
53
 
54
54
  contents = :junk
55
55
 
56
- _, err = capture_io do
56
+ _, err = verbose_capture_io do
57
57
  contents = RDoc::Encoding.read_file @tempfile.path, Encoding::US_ASCII
58
58
  end
59
59
 
@@ -97,6 +97,22 @@ class TestRDocEncoding < RDoc::TestCase
97
97
  assert_equal Encoding::UTF_8, content.encoding
98
98
  end
99
99
 
100
+ def test_class_read_file_encoding_invalid
101
+ skip "Encoding not implemented" unless Object.const_defined? :Encoding
102
+
103
+ @tempfile.write "# coding: ascii\nM\xE4r"
104
+ @tempfile.flush
105
+
106
+ contents = :junk
107
+ _, err = verbose_capture_io do
108
+ contents = RDoc::Encoding.read_file @tempfile.path, Encoding::UTF_8
109
+ end
110
+
111
+ assert_equal "unable to convert \"\\xE4\" on US-ASCII for #{@tempfile.path}, skipping\n", err
112
+
113
+ assert_nil contents
114
+ end
115
+
100
116
  def test_class_read_file_encoding_with_signature
101
117
  skip "Encoding not implemented" unless defined? ::Encoding
102
118
 
@@ -0,0 +1,94 @@
1
+ require File.expand_path '../xref_test_case', __FILE__
2
+
3
+ class TestRDocExtend < XrefTestCase
4
+
5
+ def setup
6
+ super
7
+
8
+ @ext = RDoc::Extend.new 'M1', 'comment'
9
+ @ext.parent = @m1
10
+ @ext.store = @store
11
+ end
12
+
13
+ def test_module
14
+ assert_equal @m1, @ext.module
15
+ assert_equal 'Unknown', RDoc::Extend.new('Unknown', 'comment').module
16
+ end
17
+
18
+ def test_module_extended
19
+ m1 = @xref_data.add_module RDoc::NormalModule, 'Mod1'
20
+ m1.add_module RDoc::NormalModule, 'Mod3'
21
+ m1_m2 = m1.add_module RDoc::NormalModule, 'Mod2'
22
+ m1_m2_m3 = m1_m2.add_module RDoc::NormalModule, 'Mod3'
23
+ m1_m2_m3.add_module RDoc::NormalModule, 'Mod4'
24
+ m1_m2.add_module RDoc::NormalModule, 'Mod4'
25
+ m1_m2_k0 = m1_m2.add_class RDoc::NormalClass, 'Klass0'
26
+ m1_m2_k0_m4 = m1_m2_k0.add_module RDoc::NormalModule, 'Mod4'
27
+ m1_m2_k0_m4.add_module RDoc::NormalModule, 'Mod6'
28
+ m1_m2_k0.add_module RDoc::NormalModule, 'Mod5'
29
+
30
+ e0_m4 = RDoc::Extend.new 'Mod4', nil
31
+ e0_m5 = RDoc::Extend.new 'Mod5', nil
32
+ e0_m6 = RDoc::Extend.new 'Mod6', nil
33
+ e0_m1 = RDoc::Extend.new 'Mod1', nil
34
+ e0_m2 = RDoc::Extend.new 'Mod2', nil
35
+ e0_m3 = RDoc::Extend.new 'Mod3', nil
36
+
37
+ m1_m2_k0.add_extend e0_m4
38
+ m1_m2_k0.add_extend e0_m5
39
+ m1_m2_k0.add_extend e0_m6
40
+ m1_m2_k0.add_extend e0_m1
41
+ m1_m2_k0.add_extend e0_m2
42
+ m1_m2_k0.add_extend e0_m3
43
+
44
+ assert_equal [e0_m4, e0_m5, e0_m6, e0_m1, e0_m2, e0_m3], m1_m2_k0.extends
45
+ assert_equal ['Object'], m1_m2_k0.ancestors
46
+
47
+ m1_k1 = m1.add_class RDoc::NormalClass, 'Klass1'
48
+
49
+ e1_m1 = RDoc::Extend.new 'Mod1', nil
50
+ e1_m2 = RDoc::Extend.new 'Mod2', nil
51
+ e1_m3 = RDoc::Extend.new 'Mod3', nil
52
+ e1_m4 = RDoc::Extend.new 'Mod4', nil
53
+ e1_k0_m4 = RDoc::Extend.new 'Klass0::Mod4', nil
54
+
55
+ m1_k1.add_extend e1_m1
56
+ m1_k1.add_extend e1_m2
57
+ m1_k1.add_extend e1_m3
58
+ m1_k1.add_extend e1_m4
59
+ m1_k1.add_extend e1_k0_m4
60
+
61
+ assert_equal [e1_m1, e1_m2, e1_m3, e1_m4, e1_k0_m4], m1_k1.extends
62
+ assert_equal ['Object'], m1_k1.ancestors
63
+
64
+ m1_k2 = m1.add_class RDoc::NormalClass, 'Klass2'
65
+
66
+ e2_m1 = RDoc::Extend.new 'Mod1', nil
67
+ e2_m2 = RDoc::Extend.new 'Mod2', nil
68
+ e2_m3 = RDoc::Extend.new 'Mod3', nil
69
+ e2_k0_m4 = RDoc::Extend.new 'Klass0::Mod4', nil
70
+
71
+ m1_k2.add_extend e2_m1
72
+ m1_k2.add_extend e2_m3
73
+ m1_k2.add_extend e2_m2
74
+ m1_k2.add_extend e2_k0_m4
75
+
76
+ assert_equal [e2_m1, e2_m3, e2_m2, e2_k0_m4], m1_k2.extends
77
+ assert_equal ['Object'], m1_k2.ancestors
78
+
79
+ m1_k3 = m1.add_class RDoc::NormalClass, 'Klass3'
80
+
81
+ e3_m1 = RDoc::Extend.new 'Mod1', nil
82
+ e3_m2 = RDoc::Extend.new 'Mod2', nil
83
+ e3_m4 = RDoc::Extend.new 'Mod4', nil
84
+
85
+ m1_k3.add_extend e3_m1
86
+ m1_k3.add_extend e3_m2
87
+ m1_k3.add_extend e3_m4
88
+
89
+ assert_equal [e3_m1, e3_m2, e3_m4], m1_k3.extends
90
+ assert_equal ['Object'], m1_k3.ancestors
91
+ end
92
+
93
+ end
94
+
@@ -24,17 +24,21 @@ class TestRDocGeneratorDarkfish < RDoc::TestCase
24
24
  break
25
25
  end
26
26
 
27
- rd = RDoc::RDoc.new
28
- rd.options = @options
29
- RDoc::RDoc.current = rd
27
+ @rdoc.options = @options
30
28
 
31
- @g = @options.generator.new @options
29
+ @g = @options.generator.new @store, @options
30
+ @rdoc.generator = @g
32
31
 
33
- rd.generator = @g
34
-
35
- @top_level = RDoc::TopLevel.new 'file.rb'
32
+ @top_level = @store.add_file 'file.rb'
36
33
  @top_level.parser = RDoc::Parser::Ruby
37
- @klass = @top_level.add_class RDoc::NormalClass, 'Object'
34
+ @klass = @top_level.add_class RDoc::NormalClass, 'Klass'
35
+
36
+ @alias_constant = RDoc::Constant.new 'A', nil, ''
37
+ @alias_constant.record_location @top_level
38
+
39
+ @top_level.add_constant @alias_constant
40
+
41
+ @klass.add_module_alias @klass, 'A', @top_level
38
42
 
39
43
  @meth = RDoc::AnyMethod.new nil, 'method'
40
44
  @meth_bang = RDoc::AnyMethod.new nil, 'method!'
@@ -46,6 +50,11 @@ class TestRDocGeneratorDarkfish < RDoc::TestCase
46
50
 
47
51
  @ignored = @top_level.add_class RDoc::NormalClass, 'Ignored'
48
52
  @ignored.ignore
53
+
54
+ @store.complete :private
55
+
56
+ @object = @store.find_class_or_module 'Object'
57
+ @klass_alias = @store.find_class_or_module 'Klass::A'
49
58
  end
50
59
 
51
60
  def teardown
@@ -64,11 +73,18 @@ class TestRDocGeneratorDarkfish < RDoc::TestCase
64
73
  refute File.exist?(path), "#{path} exists"
65
74
  end
66
75
 
76
+ def mu_pp obj
77
+ s = ''
78
+ s = PP.pp obj, s
79
+ s = s.force_encoding Encoding.default_external if defined? Encoding
80
+ s.chomp
81
+ end
82
+
67
83
  def test_generate
68
- top_level = RDoc::TopLevel.new 'file.rb'
84
+ top_level = @store.add_file 'file.rb'
69
85
  top_level.add_class @klass.class, @klass.name
70
86
 
71
- @g.generate [top_level]
87
+ @g.generate
72
88
 
73
89
  assert_file 'index.html'
74
90
  assert_file 'Object.html'
@@ -76,7 +92,7 @@ class TestRDocGeneratorDarkfish < RDoc::TestCase
76
92
  assert_file 'js/search_index.js'
77
93
 
78
94
  encoding = if Object.const_defined? :Encoding then
79
- Regexp.escape Encoding.default_external.name
95
+ Regexp.escape Encoding::UTF_8.name
80
96
  else
81
97
  Regexp.escape 'UTF-8'
82
98
  end
@@ -90,11 +106,11 @@ class TestRDocGeneratorDarkfish < RDoc::TestCase
90
106
  end
91
107
 
92
108
  def test_generate_dry_run
93
- @options.dry_run = true
94
- top_level = RDoc::TopLevel.new 'file.rb'
109
+ @g.dry_run = true
110
+ top_level = @store.add_file 'file.rb'
95
111
  top_level.add_class @klass.class, @klass.name
96
112
 
97
- @g.generate [top_level]
113
+ @g.generate
98
114
 
99
115
  refute_file 'index.html'
100
116
  refute_file 'Object.html'
@@ -111,7 +127,7 @@ class TestRDocGeneratorDarkfish < RDoc::TestCase
111
127
  File.expand_path('file/file.txt'),
112
128
  ]
113
129
 
114
- @g.generate [@top_level]
130
+ @g.generate
115
131
 
116
132
  assert_file 'images/image.png'
117
133
  assert_file 'file.txt'
@@ -122,17 +138,27 @@ class TestRDocGeneratorDarkfish < RDoc::TestCase
122
138
  FileUtils.touch 'static/image.png'
123
139
 
124
140
  @options.static_path = [File.expand_path('static')]
125
- @options.dry_run = true
141
+ @g.dry_run = true
126
142
 
127
- @g.generate [@top_level]
143
+ @g.generate
128
144
 
129
145
  refute_file 'image.png'
130
146
  end
131
147
 
148
+ def test_setup
149
+ @g.setup
150
+
151
+ assert_equal [@klass_alias, @ignored, @klass, @object],
152
+ @g.classes.sort_by { |klass| klass.full_name }
153
+ assert_equal [@top_level], @g.files
154
+ assert_equal [@meth, @meth, @meth_bang, @meth_bang], @g.methods
155
+ assert_equal [@klass_alias, @klass, @object], @g.modsort
156
+ end
157
+
132
158
  def test_template_for
133
159
  classpage = Pathname.new @options.template_dir + 'class.rhtml'
134
160
 
135
- template = @g.send(:template_for, classpage)
161
+ template = @g.send(:template_for, classpage, true, RDoc::ERBIO)
136
162
  assert_kind_of RDoc::ERBIO, template
137
163
 
138
164
  assert_same template, @g.send(:template_for, classpage)
@@ -141,7 +167,7 @@ class TestRDocGeneratorDarkfish < RDoc::TestCase
141
167
  def test_template_for_dry_run
142
168
  classpage = Pathname.new @options.template_dir + 'class.rhtml'
143
169
 
144
- template = @g.send(:template_for, classpage)
170
+ template = @g.send(:template_for, classpage, true, ERB)
145
171
  assert_kind_of ERB, template
146
172
 
147
173
  assert_same template, @g.send(:template_for, classpage)
@@ -19,15 +19,13 @@ class TestRDocGeneratorJsonIndex < RDoc::TestCase
19
19
  @options.option_parser = OptionParser.new
20
20
  @options.finish
21
21
 
22
- @darkfish = RDoc::Generator::Darkfish.new @options
22
+ @darkfish = RDoc::Generator::Darkfish.new @store, @options
23
23
  @g = RDoc::Generator::JsonIndex.new @darkfish, @options
24
24
 
25
- @rdoc = RDoc::RDoc.new
26
25
  @rdoc.options = @options
27
26
  @rdoc.generator = @g
28
- RDoc::RDoc.current = @rdoc
29
27
 
30
- @top_level = RDoc::TopLevel.new 'file.rb'
28
+ @top_level = @store.add_file 'file.rb'
31
29
  @top_level.parser = RDoc::Parser::Ruby
32
30
 
33
31
  @klass = @top_level.add_class RDoc::NormalClass, 'C'
@@ -43,7 +41,7 @@ class TestRDocGeneratorJsonIndex < RDoc::TestCase
43
41
  @ignored = @top_level.add_class RDoc::NormalClass, 'Ignored'
44
42
  @ignored.ignore
45
43
 
46
- @page = RDoc::TopLevel.new 'page.rdoc'
44
+ @page = @store.add_file 'page.rdoc'
47
45
  @page.parser = RDoc::Parser::Simple
48
46
 
49
47
  @top_levels = [@top_level, @page].sort
@@ -70,6 +68,28 @@ class TestRDocGeneratorJsonIndex < RDoc::TestCase
70
68
  s.chomp
71
69
  end
72
70
 
71
+ def test_build_index
72
+ index = @g.build_index
73
+
74
+ expected = {
75
+ :index => {
76
+ :searchIndex => %w[c d meth() meth() page],
77
+ :longSearchIndex => %w[c c::d c#meth() c::d#meth()],
78
+ :info => [
79
+ @klass.search_record[2..-1],
80
+ @nest_klass.search_record[2..-1],
81
+ @meth.search_record[2..-1],
82
+ @nest_meth.search_record[2..-1],
83
+ @page.search_record[2..-1],
84
+ ],
85
+ },
86
+ }
87
+
88
+ expected[:index][:longSearchIndex] << ''
89
+
90
+ assert_equal expected, index
91
+ end
92
+
73
93
  def test_class_dir
74
94
  assert_equal @darkfish.class_dir, @g.class_dir
75
95
  end
@@ -79,7 +99,7 @@ class TestRDocGeneratorJsonIndex < RDoc::TestCase
79
99
  end
80
100
 
81
101
  def test_generate
82
- @g.generate @top_levels
102
+ @g.generate
83
103
 
84
104
  assert_file 'js/searcher.js'
85
105
  assert_file 'js/navigation.js'
@@ -134,7 +154,7 @@ class TestRDocGeneratorJsonIndex < RDoc::TestCase
134
154
  text.force_encoding Encoding::ISO_8859_1
135
155
  @klass.add_comment comment(text), @top_level
136
156
 
137
- @g.generate @top_levels
157
+ @g.generate
138
158
 
139
159
  json = File.read 'js/search_index.js'
140
160
  json.force_encoding Encoding::UTF_8
@@ -5,17 +5,17 @@ class TestRDocGeneratorMarkup < RDoc::TestCase
5
5
  include RDoc::Text
6
6
  include RDoc::Generator::Markup
7
7
 
8
+ attr_reader :store
9
+
8
10
  def setup
9
11
  super
10
12
 
11
13
  @options = RDoc::Options.new
12
- @rdoc = RDoc::RDoc.new
13
14
  @rdoc.options = @options
15
+
14
16
  @parent = self
15
17
  @path = '/index.html'
16
18
  @symbols = {}
17
-
18
- RDoc::RDoc.current = @rdoc
19
19
  end
20
20
 
21
21
  def test_aref_to
@@ -6,14 +6,17 @@ class TestRDocGeneratorRI < RDoc::TestCase
6
6
  super
7
7
 
8
8
  @options = RDoc::Options.new
9
- @options.encoding = Encoding::UTF_8 if Object.const_defined? :Encoding
9
+ if Object.const_defined? :Encoding then
10
+ @options.encoding = Encoding::UTF_8
11
+ @store.encoding = Encoding::UTF_8
12
+ end
10
13
 
11
14
  @tmpdir = File.join Dir.tmpdir, "test_rdoc_generator_ri_#{$$}"
12
15
  FileUtils.mkdir_p @tmpdir
13
16
 
14
- @g = RDoc::Generator::RI.new @options
17
+ @g = RDoc::Generator::RI.new @store, @options
15
18
 
16
- @top_level = RDoc::TopLevel.new 'file.rb'
19
+ @top_level = @store.add_file 'file.rb'
17
20
  @klass = @top_level.add_class RDoc::NormalClass, 'Object'
18
21
 
19
22
  @meth = RDoc::AnyMethod.new nil, 'method'
@@ -48,7 +51,7 @@ class TestRDocGeneratorRI < RDoc::TestCase
48
51
  end
49
52
 
50
53
  def test_generate
51
- @g.generate nil
54
+ @g.generate
52
55
 
53
56
  assert_file File.join(@tmpdir, 'cache.ri')
54
57
 
@@ -67,16 +70,15 @@ class TestRDocGeneratorRI < RDoc::TestCase
67
70
  end
68
71
 
69
72
  def test_generate_dry_run
70
- @options.dry_run = true
71
- @g = RDoc::Generator::RI.new @options
73
+ @store.dry_run = true
74
+ @g = RDoc::Generator::RI.new @store, @options
72
75
 
73
- top_level = RDoc::TopLevel.new 'file.rb'
76
+ top_level = @store.add_file 'file.rb'
74
77
  top_level.add_class @klass.class, @klass.name
75
78
 
76
- @g.generate nil
79
+ @g.generate
77
80
 
78
81
  refute_file File.join(@tmpdir, 'cache.ri')
79
-
80
82
  refute_file File.join(@tmpdir, 'Object')
81
83
  end
82
84
 
@@ -7,6 +7,8 @@ class TestRDocInclude < XrefTestCase
7
7
 
8
8
  @inc = RDoc::Include.new 'M1', 'comment'
9
9
  @inc.parent = @m1
10
+ @inc.record_location @top_level
11
+ @inc.store = @store
10
12
  end
11
13
 
12
14
  def test_module
@@ -92,5 +94,15 @@ class TestRDocInclude < XrefTestCase
92
94
  assert_equal [m1_m2_m4, m1_m2, m1, 'Object'], m1_k3.ancestors
93
95
  end
94
96
 
97
+ def test_store_equals
98
+ incl = RDoc::Include.new 'M', nil
99
+ incl.record_location RDoc::TopLevel.new @top_level.name
100
+
101
+ incl.store = @store
102
+
103
+ assert_same @top_level, incl.file
104
+ assert_same @store, incl.file.store
105
+ end
106
+
95
107
  end
96
108
 
@@ -0,0 +1,977 @@
1
+ # coding: UTF-8
2
+
3
+ require 'rubygems'
4
+ require 'minitest/autorun'
5
+ require 'pp'
6
+
7
+ require 'rdoc'
8
+ require 'rdoc/markup/block_quote'
9
+ require 'rdoc/markdown'
10
+
11
+ class TestRDocMarkdown < RDoc::TestCase
12
+
13
+ def setup
14
+ @RM = RDoc::Markup
15
+
16
+ @parser = RDoc::Markdown.new
17
+ end
18
+
19
+ def mu_pp obj
20
+ s = ''
21
+ s = PP.pp obj, s
22
+ s.force_encoding Encoding.default_external if defined? Encoding
23
+ s.chomp
24
+ end
25
+
26
+ def test_class_parse
27
+ doc = RDoc::Markdown.parse "hello\n\nworld"
28
+
29
+ expected = doc(para("hello"), para("world"))
30
+
31
+ assert_equal expected, doc
32
+ end
33
+
34
+ def test_emphasis
35
+ assert_equal '_word_', @parser.emphasis('word')
36
+ assert_equal '<em>two words</em>', @parser.emphasis('two words')
37
+ assert_equal '<em>*bold*</em>', @parser.emphasis('*bold*')
38
+ end
39
+
40
+ def test_parse_auto_link_email
41
+ doc = parse "Autolink: <nobody-0+_./!%~$@example>"
42
+
43
+ expected = doc(para("Autolink: mailto:nobody-0+_./!%~$@example"))
44
+
45
+ assert_equal expected, doc
46
+ end
47
+
48
+ def test_parse_auto_link_url
49
+ doc = parse "Autolink: <http://example>"
50
+
51
+ expected = doc(para("Autolink: http://example"))
52
+
53
+ assert_equal expected, doc
54
+ end
55
+
56
+ def test_parse_block_quote
57
+ doc = parse <<-BLOCK_QUOTE
58
+ > this is
59
+ > a block quote
60
+ BLOCK_QUOTE
61
+
62
+ expected =
63
+ doc(
64
+ block(
65
+ para("this is\na block quote")))
66
+
67
+ assert_equal expected, doc
68
+ end
69
+
70
+ def test_parse_block_quote_continue
71
+ doc = parse <<-BLOCK_QUOTE
72
+ > this is
73
+ a block quote
74
+ BLOCK_QUOTE
75
+
76
+ expected =
77
+ doc(
78
+ block(
79
+ para("this is\na block quote")))
80
+
81
+ assert_equal expected, doc
82
+ end
83
+
84
+ def test_parse_block_quote_list
85
+ doc = parse <<-BLOCK_QUOTE
86
+ > text
87
+ >
88
+ > * one
89
+ > * two
90
+ BLOCK_QUOTE
91
+
92
+ expected =
93
+ doc(
94
+ block(
95
+ para("text"),
96
+ list(:BULLET,
97
+ item(nil, para("one")),
98
+ item(nil, para("two")))))
99
+
100
+ assert_equal expected, doc
101
+ end
102
+
103
+ def test_parse_block_quote_newline
104
+ doc = parse <<-BLOCK_QUOTE
105
+ > this is
106
+ a block quote
107
+
108
+ BLOCK_QUOTE
109
+
110
+ expected =
111
+ doc(
112
+ block(
113
+ para("this is\na block quote")))
114
+
115
+ assert_equal expected, doc
116
+ end
117
+
118
+ def test_parse_block_quote_separate
119
+ doc = parse <<-BLOCK_QUOTE
120
+ > this is
121
+ a block quote
122
+
123
+ > that continues
124
+ BLOCK_QUOTE
125
+
126
+ expected =
127
+ doc(
128
+ block(
129
+ para("this is\na block quote"),
130
+ para("that continues")))
131
+
132
+ assert_equal expected, doc
133
+ end
134
+
135
+ def test_parse_char_entity
136
+ doc = parse '&pi; &nn;'
137
+
138
+ expected = doc(para('π &nn;'))
139
+
140
+ assert_equal expected, doc
141
+ end
142
+
143
+ def test_parse_code
144
+ doc = parse "Code: `text`"
145
+
146
+ expected = doc(para("Code: <code>text</code>"))
147
+
148
+ assert_equal expected, doc
149
+ end
150
+
151
+ def test_parse_code_github
152
+ doc = parse <<-MD
153
+ Example:
154
+
155
+ ```
156
+ code goes here
157
+ ```
158
+ MD
159
+
160
+ expected =
161
+ doc(
162
+ para("Example:"),
163
+ verb("code goes here\n"))
164
+
165
+ assert_equal expected, doc
166
+ end
167
+
168
+ def test_parse_code_github_format
169
+ doc = parse <<-MD
170
+ Example:
171
+
172
+ ``` ruby
173
+ code goes here
174
+ ```
175
+ MD
176
+
177
+ code = verb("code goes here\n")
178
+ code.format = :ruby
179
+
180
+ expected =
181
+ doc(
182
+ para("Example:"),
183
+ code)
184
+
185
+ assert_equal expected, doc
186
+ end
187
+
188
+ def test_parse_definition_list
189
+ doc = parse <<-MD
190
+ one
191
+ : This is a definition
192
+
193
+ two
194
+ : This is another definition
195
+ MD
196
+
197
+ expected = doc(
198
+ list(:NOTE,
199
+ item(%w[one], para("This is a definition")),
200
+ item(%w[two], para("This is another definition"))))
201
+
202
+ assert_equal expected, doc
203
+ end
204
+
205
+ def test_parse_definition_list_indents
206
+ doc = parse <<-MD
207
+ zero
208
+ : Indented zero characters
209
+
210
+ one
211
+ : Indented one characters
212
+
213
+ two
214
+ : Indented two characters
215
+
216
+ three
217
+ : Indented three characters
218
+
219
+ four
220
+ : Indented four characters
221
+
222
+ MD
223
+
224
+ expected = doc(
225
+ list(:NOTE,
226
+ item(%w[zero], para("Indented zero characters")),
227
+ item(%w[one], para("Indented one characters")),
228
+ item(%w[two], para("Indented two characters")),
229
+ item(%w[three], para("Indented three characters"))),
230
+ para("four\n : Indented four characters"))
231
+
232
+ assert_equal expected, doc
233
+ end
234
+
235
+ def test_parse_definition_list_multi_description
236
+ doc = parse <<-MD
237
+ label
238
+ : This is a definition
239
+
240
+ : This is another definition
241
+ MD
242
+
243
+ expected = doc(
244
+ list(:NOTE,
245
+ item(%w[label], para("This is a definition")),
246
+ item(nil, para("This is another definition"))))
247
+
248
+ assert_equal expected, doc
249
+ end
250
+
251
+ def test_parse_definition_list_multi_label
252
+ doc = parse <<-MD
253
+ one
254
+ two
255
+ : This is a definition
256
+ MD
257
+
258
+ expected = doc(
259
+ list(:NOTE,
260
+ item(%w[one two], para("This is a definition"))))
261
+
262
+ assert_equal expected, doc
263
+ end
264
+
265
+ def test_parse_definition_list_multi_line
266
+ doc = parse <<-MD
267
+ one
268
+ : This is a definition
269
+ that extends to two lines
270
+
271
+ two
272
+ : This is another definition
273
+ that also extends to two lines
274
+ MD
275
+
276
+ expected = doc(
277
+ list(:NOTE,
278
+ item(%w[one],
279
+ para("This is a definition\nthat extends to two lines")),
280
+ item(%w[two],
281
+ para("This is another definition\nthat also extends to two lines"))))
282
+
283
+ assert_equal expected, doc
284
+ end
285
+
286
+ def test_parse_definition_list_no
287
+ @parser.definition_lists = false
288
+
289
+ doc = parse <<-MD
290
+ one
291
+ : This is a definition
292
+
293
+ two
294
+ : This is another definition
295
+ MD
296
+
297
+ expected = doc(
298
+ para("one\n: This is a definition"),
299
+ para("two\n: This is another definition"))
300
+
301
+ assert_equal expected, doc
302
+ end
303
+
304
+ def test_parse_entity_dec
305
+ doc = parse "Entity: &#65;"
306
+
307
+ expected = doc(para("Entity: A"))
308
+
309
+ assert_equal expected, doc
310
+ end
311
+
312
+ def test_parse_entity_hex
313
+ doc = parse "Entity: &#x41;"
314
+
315
+ expected = doc(para("Entity: A"))
316
+
317
+ assert_equal expected, doc
318
+ end
319
+
320
+ def test_parse_entity_named
321
+ doc = parse "Entity: &pi;"
322
+
323
+ expected = doc(para("Entity: π"))
324
+
325
+ assert_equal expected, doc
326
+ end
327
+
328
+ def test_parse_emphasis_star
329
+ doc = parse "it *works*\n"
330
+
331
+ expected = @RM::Document.new(
332
+ @RM::Paragraph.new("it _works_"))
333
+
334
+ assert_equal expected, doc
335
+ end
336
+
337
+ def test_parse_emphasis_underscore
338
+ doc = parse "it _works_\n"
339
+
340
+ expected =
341
+ doc(
342
+ para("it _works_"))
343
+
344
+ assert_equal expected, doc
345
+ end
346
+
347
+ def test_parse_emphasis_underscore_embedded
348
+ doc = parse "foo_bar bar_baz\n"
349
+
350
+ expected =
351
+ doc(
352
+ para("foo_bar bar_baz"))
353
+
354
+ assert_equal expected, doc
355
+ end
356
+
357
+ def test_parse_emphasis_underscore_in_word
358
+ doc = parse "it foo_bar_baz\n"
359
+
360
+ expected =
361
+ doc(
362
+ para("it foo_bar_baz"))
363
+
364
+ assert_equal expected, doc
365
+ end
366
+
367
+ def test_parse_escape
368
+ assert_equal doc(para("Backtick: `")), parse("Backtick: \\`")
369
+
370
+ assert_equal doc(para("Backslash: \\")), parse("Backslash: \\\\")
371
+
372
+ assert_equal doc(para("Colon: :")), parse("Colon: \\:")
373
+ end
374
+
375
+ def test_parse_heading_atx
376
+ doc = parse "# heading\n"
377
+
378
+ expected = @RM::Document.new(
379
+ @RM::Heading.new(1, "heading"))
380
+
381
+ assert_equal expected, doc
382
+ end
383
+
384
+ def test_parse_heading_setext_dash
385
+ doc = parse <<-MD
386
+ heading
387
+ ---
388
+ MD
389
+
390
+ expected = @RM::Document.new(
391
+ @RM::Heading.new(2, "heading"))
392
+
393
+ assert_equal expected, doc
394
+ end
395
+
396
+ def test_parse_heading_setext_equals
397
+ doc = parse <<-MD
398
+ heading
399
+ ===
400
+ MD
401
+
402
+ expected = @RM::Document.new(
403
+ @RM::Heading.new(1, "heading"))
404
+
405
+ assert_equal expected, doc
406
+ end
407
+
408
+ def test_parse_html
409
+ @parser.html = true
410
+
411
+ doc = parse "<address>Links here</address>\n"
412
+
413
+ expected = doc(
414
+ @RM::Raw.new("<address>Links here</address>"))
415
+
416
+ assert_equal expected, doc
417
+ end
418
+
419
+ def test_parse_html_hr
420
+ @parser.html = true
421
+
422
+ doc = parse "<hr>\n"
423
+
424
+ expected = doc(raw("<hr>"))
425
+
426
+ assert_equal expected, doc
427
+ end
428
+
429
+ def test_parse_html_no_html
430
+ @parser.html = false
431
+
432
+ doc = parse "<address>Links here</address>\n"
433
+
434
+ expected = doc()
435
+
436
+ assert_equal expected, doc
437
+ end
438
+
439
+ def test_parse_image
440
+ doc = parse "image ![alt text](path/to/image.jpg)"
441
+
442
+ expected = doc(para("image {alt text}[path/to/image.jpg]"))
443
+
444
+ assert_equal expected, doc
445
+ end
446
+
447
+ def test_parse_line_break
448
+ doc = parse "Some text \nwith extra lines"
449
+
450
+ expected = doc(
451
+ para("Some text", hard_break, "with extra lines"))
452
+
453
+ assert_equal expected, doc
454
+ end
455
+
456
+ def test_parse_link_reference_id
457
+ doc = parse <<-MD
458
+ This is [an example][id] reference-style link.
459
+
460
+ [id]: http://example.com "Optional Title Here"
461
+ MD
462
+
463
+ expected = doc(
464
+ para("This is {an example}[http://example.com] reference-style link."))
465
+
466
+ assert_equal expected, doc
467
+ end
468
+
469
+ def test_parse_link_reference_id_adjacent
470
+ doc = parse <<-MD
471
+ [this] [this] should work
472
+
473
+ [this]: example
474
+ MD
475
+
476
+ expected = doc(
477
+ para("{this}[example] should work"))
478
+
479
+ assert_equal expected, doc
480
+ end
481
+
482
+ def test_parse_link_reference_id_eof
483
+ doc = parse <<-MD.chomp
484
+ This is [an example][id] reference-style link.
485
+
486
+ [id]: http://example.com "Optional Title Here"
487
+ MD
488
+
489
+ expected = doc(
490
+ para("This is {an example}[http://example.com] reference-style link."))
491
+
492
+ assert_equal expected, doc
493
+ end
494
+
495
+ def test_parse_link_reference_id_many
496
+ doc = parse <<-MD
497
+ This is [an example][id] reference-style link.
498
+
499
+ And [another][id].
500
+
501
+ [id]: http://example.com "Optional Title Here"
502
+ MD
503
+
504
+ expected = doc(
505
+ para("This is {an example}[http://example.com] reference-style link."),
506
+ para("And {another}[http://example.com]."))
507
+
508
+ assert_equal expected, doc
509
+ end
510
+
511
+ def test_parse_link_reference_implicit
512
+ doc = parse <<-MD
513
+ This is [an example][] reference-style link.
514
+
515
+ [an example]: http://example.com "Optional Title Here"
516
+ MD
517
+
518
+ expected = doc(
519
+ para("This is {an example}[http://example.com] reference-style link."))
520
+
521
+ assert_equal expected, doc
522
+ end
523
+
524
+ def test_parse_list_bullet
525
+ doc = parse <<-MD
526
+ * one
527
+ * two
528
+ MD
529
+
530
+ expected = doc(
531
+ list(:BULLET,
532
+ item(nil, para("one")),
533
+ item(nil, para("two"))))
534
+
535
+ assert_equal expected, doc
536
+ end
537
+
538
+ def test_parse_list_bullet_auto_link
539
+ doc = parse <<-MD
540
+ * <http://example/>
541
+ MD
542
+
543
+ expected = doc(
544
+ list(:BULLET,
545
+ item(nil, para("http://example/"))))
546
+
547
+ assert_equal expected, doc
548
+ end
549
+
550
+ def test_parse_list_bullet_continue
551
+ doc = parse <<-MD
552
+ * one
553
+
554
+ * two
555
+ MD
556
+
557
+ expected = doc(
558
+ list(:BULLET,
559
+ item(nil, para("one")),
560
+ item(nil, para("two"))))
561
+
562
+ assert_equal expected, doc
563
+ end
564
+
565
+ def test_parse_list_bullet_multiline
566
+ doc = parse <<-MD
567
+ * one
568
+ two
569
+ MD
570
+
571
+ expected = doc(
572
+ list(:BULLET,
573
+ item(nil, para("one\n two"))))
574
+
575
+ assert_equal expected, doc
576
+ end
577
+
578
+ def test_parse_list_bullet_nest
579
+ doc = parse <<-MD
580
+ * outer
581
+ * inner
582
+ MD
583
+
584
+ expected = doc(
585
+ list(:BULLET,
586
+ item(nil,
587
+ para("outer"),
588
+ list(:BULLET,
589
+ item(nil,
590
+ para("inner"))))))
591
+
592
+ assert_equal expected, doc
593
+ end
594
+
595
+ def test_parse_list_bullet_nest_loose
596
+ doc = parse <<-MD
597
+ * outer
598
+
599
+ * inner
600
+ MD
601
+
602
+ expected = doc(
603
+ list(:BULLET,
604
+ item(nil,
605
+ para("outer"),
606
+ list(:BULLET,
607
+ item(nil, para("inner"))))))
608
+
609
+ assert_equal expected, doc
610
+ end
611
+
612
+ def test_parse_list_bullet_nest_continue
613
+ doc = parse <<-MD
614
+ * outer
615
+ * inner
616
+ continue inner
617
+ * outer 2
618
+ MD
619
+
620
+ expected = doc(
621
+ list(:BULLET,
622
+ item(nil,
623
+ para("outer"),
624
+ list(:BULLET,
625
+ item(nil,
626
+ para("inner\n continue inner")))),
627
+ item(nil,
628
+ para("outer 2"))))
629
+
630
+ assert_equal expected, doc
631
+ end
632
+
633
+ def test_parse_list_number
634
+ doc = parse <<-MD
635
+ 1. one
636
+ 1. two
637
+ MD
638
+
639
+ expected = doc(
640
+ list(:NUMBER,
641
+ item(nil, para("one")),
642
+ item(nil, para("two"))))
643
+
644
+ assert_equal expected, doc
645
+ end
646
+
647
+ def test_parse_list_number_continue
648
+ doc = parse <<-MD
649
+ 1. one
650
+
651
+ 1. two
652
+ MD
653
+
654
+ expected = doc(
655
+ list(:NUMBER,
656
+ item(nil, para("one")),
657
+ item(nil, para("two"))))
658
+
659
+ assert_equal expected, doc
660
+ end
661
+
662
+ def test_parse_note
663
+ @parser.notes = true
664
+
665
+ doc = parse <<-MD
666
+ Some text.[^1]
667
+
668
+ [^1]: With a footnote
669
+ MD
670
+
671
+ expected = doc(
672
+ para("Some text.{*1}[rdoc-label:foottext-1:footmark-1]"),
673
+ @RM::Rule.new(1),
674
+ para("{^1}[rdoc-label:footmark-1:foottext-1] With a footnote"))
675
+
676
+ assert_equal expected, doc
677
+ end
678
+
679
+ def test_parse_note_indent
680
+ @parser.notes = true
681
+
682
+ doc = parse <<-MD
683
+ Some text.[^1]
684
+
685
+ [^1]: With a footnote
686
+
687
+ more
688
+ MD
689
+
690
+ expected = doc(
691
+ para("Some text.{*1}[rdoc-label:foottext-1:footmark-1]"),
692
+ rule(1),
693
+ para("{^1}[rdoc-label:footmark-1:foottext-1] With a footnote\n\nmore"))
694
+
695
+ assert_equal expected, doc
696
+ end
697
+
698
+ def test_parse_note_inline
699
+ @parser.notes = true
700
+
701
+ doc = parse <<-MD
702
+ Some text. ^[With a footnote]
703
+ MD
704
+
705
+ expected = doc(
706
+ para("Some text. {*1}[rdoc-label:foottext-1:footmark-1]"),
707
+ @RM::Rule.new(1),
708
+ para("{^1}[rdoc-label:footmark-1:foottext-1] With a footnote"))
709
+
710
+ assert_equal expected, doc
711
+ end
712
+
713
+ def test_parse_note_no_notes
714
+ @parser.notes = false
715
+
716
+ assert_raises RuntimeError do # TODO use a real error
717
+ parse "Some text.[^1]"
718
+ end
719
+ end
720
+
721
+ def test_parse_note_multiple
722
+ @parser.notes = true
723
+
724
+ doc = parse <<-MD
725
+ Some text[^1]
726
+ with inline notes^[like this]
727
+ and an extra note.[^2]
728
+
729
+ [^1]: With a footnote
730
+
731
+ [^2]: Which should be numbered correctly
732
+ MD
733
+
734
+ expected = doc(
735
+ para("Some text{*1}[rdoc-label:foottext-1:footmark-1]\n" +
736
+ "with inline notes{*2}[rdoc-label:foottext-2:footmark-2]\n" +
737
+ "and an extra note.{*3}[rdoc-label:foottext-3:footmark-3]"),
738
+
739
+ rule(1),
740
+
741
+ para("{^1}[rdoc-label:footmark-1:foottext-1] With a footnote"),
742
+ para("{^2}[rdoc-label:footmark-2:foottext-2] like this"),
743
+ para("{^3}[rdoc-label:footmark-3:foottext-3] " +
744
+ "Which should be numbered correctly"))
745
+
746
+ assert_equal expected, doc
747
+ end
748
+
749
+ def test_parse_paragraph
750
+ doc = parse "it worked\n"
751
+
752
+ expected = doc(para("it worked"))
753
+
754
+ assert_equal expected, doc
755
+ end
756
+
757
+ def test_parse_paragraph_break_on_newline
758
+ @parser.break_on_newline = true
759
+
760
+ doc = parse "one\ntwo\n"
761
+
762
+ expected = doc(para("one", hard_break, "two"))
763
+
764
+ assert_equal expected, doc
765
+
766
+ doc = parse "one \ntwo\nthree\n"
767
+
768
+ expected = doc(para("one", hard_break, "two", hard_break, "three"))
769
+
770
+ assert_equal expected, doc
771
+ end
772
+
773
+ def test_parse_paragraph_stars
774
+ doc = parse "it worked ****\n"
775
+
776
+ expected = @RM::Document.new(
777
+ @RM::Paragraph.new("it worked ****"))
778
+
779
+ assert_equal expected, doc
780
+ end
781
+
782
+ def test_parse_paragraph_html
783
+ @parser.html = true
784
+
785
+ doc = parse "<address>Links here</address>"
786
+
787
+ expected = doc(raw("<address>Links here</address>"))
788
+
789
+ assert_equal expected, doc
790
+ end
791
+
792
+ def test_parse_paragraph_html_no_html
793
+ @parser.html = false
794
+
795
+ doc = parse "<address>Links here</address>"
796
+
797
+ expected = doc()
798
+
799
+ assert_equal expected, doc
800
+ end
801
+
802
+ def test_parse_paragraph_indent_one
803
+ doc = parse <<-MD
804
+ text
805
+ MD
806
+
807
+ expected = doc(para("text"))
808
+
809
+ assert_equal expected, doc
810
+ end
811
+
812
+ def test_parse_paragraph_indent_two
813
+ doc = parse <<-MD
814
+ text
815
+ MD
816
+
817
+ expected = doc(para("text"))
818
+
819
+ assert_equal expected, doc
820
+ end
821
+
822
+ def test_parse_paragraph_indent_three
823
+ doc = parse <<-MD
824
+ text
825
+ MD
826
+
827
+ expected = doc(para("text"))
828
+
829
+ assert_equal expected, doc
830
+ end
831
+
832
+ def test_parse_paragraph_multiline
833
+ doc = parse "one\ntwo"
834
+
835
+ expected = doc(para("one\ntwo"))
836
+
837
+ assert_equal expected, doc
838
+ end
839
+
840
+ def test_parse_paragraph_two
841
+ doc = parse "one\n\ntwo"
842
+
843
+ expected = @RM::Document.new(
844
+ @RM::Paragraph.new("one"),
845
+ @RM::Paragraph.new("two"))
846
+
847
+ assert_equal expected, doc
848
+ end
849
+
850
+ def test_parse_plain
851
+ doc = parse "it worked"
852
+
853
+ expected = @RM::Document.new(
854
+ @RM::Paragraph.new("it worked"))
855
+
856
+ assert_equal expected, doc
857
+ end
858
+
859
+ def test_parse_reference_link_embedded_bracket
860
+ doc = parse "With [embedded [brackets]] [b].\n\n[b]: /url/\n"
861
+
862
+ expected =
863
+ doc(
864
+ para("With {embedded [brackets]}[/url/]."))
865
+
866
+ assert_equal expected, doc
867
+ end
868
+
869
+ def test_parse_rule_dash
870
+ doc = parse "- - -\n\n"
871
+
872
+ expected = @RM::Document.new(@RM::Rule.new(1))
873
+
874
+ assert_equal expected, doc
875
+ end
876
+
877
+ def test_parse_rule_underscore
878
+ doc = parse "_ _ _\n\n"
879
+
880
+ expected = @RM::Document.new(@RM::Rule.new(1))
881
+
882
+ assert_equal expected, doc
883
+ end
884
+
885
+ def test_parse_rule_star
886
+ doc = parse "* * *\n\n"
887
+
888
+ expected = @RM::Document.new(@RM::Rule.new(1))
889
+
890
+ assert_equal expected, doc
891
+ end
892
+
893
+ def test_parse_strong_star
894
+ doc = parse "it **works**\n"
895
+
896
+ expected = @RM::Document.new(
897
+ @RM::Paragraph.new("it *works*"))
898
+
899
+ assert_equal expected, doc
900
+ end
901
+
902
+ def test_parse_strong_underscore
903
+ doc = parse "it __works__\n"
904
+
905
+ expected = @RM::Document.new(
906
+ @RM::Paragraph.new("it *works*"))
907
+
908
+ assert_equal expected, doc
909
+ end
910
+
911
+ def test_parse_strong_emphasis_star
912
+ doc = parse "it ***works***\n"
913
+
914
+ expected = @RM::Document.new(
915
+ @RM::Paragraph.new("it <b>_works_</b>"))
916
+
917
+ assert_equal expected, doc
918
+ end
919
+
920
+ def test_parse_strong_emphasis_underscore
921
+ doc = parse "it ___works___\n"
922
+
923
+ expected = @RM::Document.new(
924
+ @RM::Paragraph.new("it <b>_works_</b>"))
925
+
926
+ assert_equal expected, doc
927
+ end
928
+
929
+ def test_parse_style
930
+ @parser.css = true
931
+
932
+ doc = parse "<style>h1 { color: red }</style>\n"
933
+
934
+ expected = doc(
935
+ @RM::Raw.new("<style>h1 { color: red }</style>"))
936
+
937
+ assert_equal expected, doc
938
+ end
939
+
940
+ def test_parse_style_disabled
941
+ doc = parse "<style>h1 { color: red }</style>\n"
942
+
943
+ expected = doc()
944
+
945
+ assert_equal expected, doc
946
+ end
947
+
948
+ def test_parse_verbatim
949
+ doc = parse <<-MD
950
+ text
951
+ MD
952
+
953
+ expected = doc(verb("text\n"))
954
+
955
+ assert_equal expected, doc
956
+ end
957
+
958
+ def test_parse_verbatim_eof
959
+ doc = parse " text"
960
+
961
+ expected = doc(verb("text\n"))
962
+
963
+ assert_equal expected, doc
964
+ end
965
+
966
+ def test_strong
967
+ assert_equal '*word*', @parser.strong('word')
968
+ assert_equal '<b>two words</b>', @parser.strong('two words')
969
+ assert_equal '<b>_emphasis_</b>', @parser.strong('_emphasis_')
970
+ end
971
+
972
+ def parse text
973
+ @parser.parse text
974
+ end
975
+
976
+ end
977
+