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
@@ -1,6 +1,6 @@
1
- require 'rdoc/test_case'
1
+ require File.expand_path '../xref_test_case', __FILE__
2
2
 
3
- class TestRDocRIStore < RDoc::TestCase
3
+ class TestRDocStore < XrefTestCase
4
4
 
5
5
  OBJECT_ANCESTORS = defined?(::BasicObject) ? %w[BasicObject] : []
6
6
 
@@ -10,7 +10,11 @@ class TestRDocRIStore < RDoc::TestCase
10
10
  @tmpdir = File.join Dir.tmpdir, "test_rdoc_ri_store_#{$$}"
11
11
  @s = RDoc::RI::Store.new @tmpdir
12
12
 
13
- @top_level = RDoc::TopLevel.new 'file.rb'
13
+ @top_level = @s.add_file 'file.rb'
14
+
15
+ @page = @s.add_file 'README.txt'
16
+ @page.parser = RDoc::Parser::Simple
17
+ @page.comment = RDoc::Comment.new 'This is a page', @page
14
18
 
15
19
  @klass = @top_level.add_class RDoc::NormalClass, 'Object'
16
20
  @klass.add_comment 'original', @top_level
@@ -19,14 +23,27 @@ class TestRDocRIStore < RDoc::TestCase
19
23
  @cmeth.singleton = true
20
24
  @cmeth.record_location @top_level
21
25
 
26
+ @meth_comment = RDoc::Comment.new 'method comment'
27
+ @meth_comment.location = @top_level
28
+
22
29
  @meth = RDoc::AnyMethod.new nil, 'method'
23
30
  @meth.record_location @top_level
31
+ @meth.comment = @meth_comment
24
32
 
25
33
  @meth_bang = RDoc::AnyMethod.new nil, 'method!'
26
34
  @meth_bang.record_location @top_level
27
35
 
36
+ @meth_bang_alias = RDoc::Alias.new nil, 'method!', 'method_bang', ''
37
+ @meth_bang_alias.record_location @top_level
38
+
39
+ @meth_bang.add_alias @meth_bang_alias, @klass
40
+
41
+ @attr_comment = RDoc::Comment.new 'attribute comment'
42
+ @attr_comment.location = @top_level
43
+
28
44
  @attr = RDoc::Attr.new nil, 'attr', 'RW', ''
29
45
  @attr.record_location @top_level
46
+ @attr.comment = @attr_comment
30
47
 
31
48
  @klass.add_method @cmeth
32
49
  @klass.add_method @meth
@@ -42,6 +59,9 @@ class TestRDocRIStore < RDoc::TestCase
42
59
 
43
60
  @nest_klass.add_method @nest_meth
44
61
  @nest_klass.add_include @nest_incl
62
+
63
+ @mod = @top_level.add_module RDoc::NormalModule, 'Mod'
64
+ @mod.record_location @top_level
45
65
  end
46
66
 
47
67
  def teardown
@@ -57,8 +77,9 @@ class TestRDocRIStore < RDoc::TestCase
57
77
  s.chomp
58
78
  end
59
79
 
60
- def assert_cache imethods, cmethods, attrs, modules, ancestors = {}
61
- imethods ||= { 'Object' => %w[method method!] }
80
+ def assert_cache imethods, cmethods, attrs, modules,
81
+ ancestors = {}, pages = [], main = nil, title = nil
82
+ imethods ||= { 'Object' => %w[method method! method_bang] }
62
83
  cmethods ||= { 'Object' => %w[cmethod] }
63
84
  attrs ||= { 'Object' => ['attr_accessor attr'] }
64
85
 
@@ -72,6 +93,9 @@ class TestRDocRIStore < RDoc::TestCase
72
93
  :encoding => nil,
73
94
  :instance_methods => imethods,
74
95
  :modules => modules,
96
+ :pages => pages,
97
+ :main => main,
98
+ :title => title,
75
99
  }
76
100
 
77
101
  @s.save_cache
@@ -91,6 +115,55 @@ class TestRDocRIStore < RDoc::TestCase
91
115
  refute File.exist?(path), "#{path} exists"
92
116
  end
93
117
 
118
+ def test_add_file
119
+ top_level = @store.add_file 'file.rb'
120
+
121
+ assert_kind_of RDoc::TopLevel, top_level
122
+ assert_equal @store, top_level.store
123
+ assert_equal 'file.rb', top_level.name
124
+ assert_includes @store.all_files, top_level
125
+
126
+ assert_same top_level, @store.add_file('file.rb')
127
+ refute_same top_level, @store.add_file('other.rb')
128
+ end
129
+
130
+ def test_add_file_relative
131
+ top_level = @store.add_file 'path/file.rb', 'file.rb'
132
+
133
+ assert_kind_of RDoc::TopLevel, top_level
134
+ assert_equal @store, top_level.store
135
+
136
+ assert_equal 'path/file.rb', top_level.absolute_name
137
+ assert_equal 'file.rb', top_level.relative_name
138
+
139
+ assert_includes @store.all_files, top_level
140
+
141
+ assert_same top_level, @store.add_file('file.rb')
142
+ refute_same top_level, @store.add_file('other.rb')
143
+ end
144
+
145
+ def test_all_classes_and_modules
146
+ expected = %w[
147
+ C1 C2 C2::C3 C2::C3::H1 C3 C3::H1 C3::H2 C4 C4::C4 C5 C5::C1
148
+ Child
149
+ M1 M1::M2
150
+ Parent
151
+ ]
152
+
153
+ assert_equal expected,
154
+ @store.all_classes_and_modules.map { |m| m.full_name }.sort
155
+ end
156
+
157
+ def test_all_files
158
+ assert_equal %w[xref_data.rb],
159
+ @store.all_files.map { |m| m.full_name }.sort
160
+ end
161
+
162
+ def test_all_modules
163
+ assert_equal %w[M1 M1::M2],
164
+ @store.all_modules.map { |m| m.full_name }.sort
165
+ end
166
+
94
167
  def test_attributes
95
168
  @s.cache[:attributes]['Object'] = %w[attr]
96
169
 
@@ -120,12 +193,63 @@ class TestRDocRIStore < RDoc::TestCase
120
193
  @s.class_path('Object::SubClass')
121
194
  end
122
195
 
123
- def test_dry_run
124
- refute @s.dry_run
196
+ def test_classes
197
+ expected = %w[
198
+ C1 C2 C2::C3 C2::C3::H1 C3 C3::H1 C3::H2 C4 C4::C4 C5 C5::C1
199
+ Child
200
+ Parent
201
+ ]
125
202
 
126
- @s.dry_run = true
203
+ assert_equal expected, @store.all_classes.map { |m| m.full_name }.sort
204
+ end
127
205
 
128
- assert @s.dry_run
206
+ def test_complete
207
+ @c2.add_module_alias @c2_c3, 'A1', @top_level
208
+
209
+ @store.complete :public
210
+
211
+ a1 = @xref_data.find_class_or_module 'C2::A1'
212
+
213
+ assert_equal 'C2::A1', a1.full_name
214
+ refute_empty a1.aliases
215
+ end
216
+
217
+ def test_find_class_named
218
+ assert_equal @c1, @store.find_class_named('C1')
219
+
220
+ assert_equal @c2_c3, @store.find_class_named('C2::C3')
221
+ end
222
+
223
+ def test_find_class_named_from
224
+ assert_equal @c5_c1, @store.find_class_named_from('C1', 'C5')
225
+
226
+ assert_equal @c1, @store.find_class_named_from('C1', 'C4')
227
+ end
228
+
229
+ def test_find_class_or_module
230
+ assert_equal @m1, @store.find_class_or_module('M1')
231
+ assert_equal @c1, @store.find_class_or_module('C1')
232
+
233
+ assert_equal @m1, @store.find_class_or_module('::M1')
234
+ assert_equal @c1, @store.find_class_or_module('::C1')
235
+ end
236
+
237
+ def test_find_file_named
238
+ assert_equal @xref_data, @store.find_file_named(@file_name)
239
+ end
240
+
241
+ def test_find_module_named
242
+ assert_equal @m1, @store.find_module_named('M1')
243
+ assert_equal @m1_m2, @store.find_module_named('M1::M2')
244
+ end
245
+
246
+ def test_find_text_page
247
+ page = @store.add_file 'PAGE.txt'
248
+ page.parser = RDoc::Parser::Simple
249
+
250
+ assert_nil @store.find_text_page 'no such page'
251
+
252
+ assert_equal page, @store.find_text_page('PAGE.txt')
129
253
  end
130
254
 
131
255
  def test_friendly_path
@@ -143,13 +267,21 @@ class TestRDocRIStore < RDoc::TestCase
143
267
  assert_equal "ruby site", @s.friendly_path
144
268
 
145
269
  @s.type = :home
146
- assert_equal "~/.ri", @s.friendly_path
270
+ assert_equal "~/.rdoc", @s.friendly_path
147
271
 
148
272
  @s.type = :gem
149
273
  @s.path = "#{@tmpdir}/gem_repository/doc/gem_name-1.0/ri"
150
274
  assert_equal "gem gem_name-1.0", @s.friendly_path
151
275
  end
152
276
 
277
+ def test_dry_run
278
+ refute @s.dry_run
279
+
280
+ @s.dry_run = true
281
+
282
+ assert @s.dry_run
283
+ end
284
+
153
285
  def test_instance_methods
154
286
  @s.cache[:instance_methods]['Object'] = %w[method]
155
287
 
@@ -158,11 +290,50 @@ class TestRDocRIStore < RDoc::TestCase
158
290
  assert_equal expected, @s.instance_methods
159
291
  end
160
292
 
293
+ def test_load_all
294
+ FileUtils.mkdir_p @tmpdir
295
+
296
+ @s.save
297
+
298
+ s = RDoc::Store.new @tmpdir
299
+
300
+ s.load_all
301
+
302
+ assert_equal [@klass, @nest_klass], s.all_classes.sort
303
+ assert_equal [@mod], s.all_modules.sort
304
+ assert_equal [@page, @top_level], s.all_files.sort
305
+
306
+ methods = s.all_classes_and_modules.map do |mod|
307
+ mod.method_list
308
+ end.flatten.sort
309
+
310
+ _meth_bang_alias = RDoc::AnyMethod.new nil, 'method_bang'
311
+ _meth_bang_alias.parent = @klass
312
+
313
+ assert_equal [@meth, @meth_bang, _meth_bang_alias, @nest_meth, @cmeth],
314
+ methods.sort_by { |m| m.full_name }
315
+
316
+ method = methods.find { |m| m == @meth }
317
+ assert_equal @meth_comment.parse, method.comment
318
+
319
+ assert_equal @klass, methods.last.parent
320
+
321
+ attributes = s.all_classes_and_modules.map do |mod|
322
+ mod.attributes
323
+ end.flatten.sort
324
+
325
+ assert_equal [@attr], attributes
326
+
327
+ assert_equal @attr_comment.parse, attributes.first.comment
328
+ end
329
+
161
330
  def test_load_cache
162
331
  cache = {
163
332
  :encoding => :encoding_value,
164
- :methods => %w[Object#method],
333
+ :methods => { "Object" => %w[Object#method] },
334
+ :main => @page.full_name,
165
335
  :modules => %w[Object],
336
+ :pages => [],
166
337
  }
167
338
 
168
339
  Dir.mkdir @tmpdir
@@ -176,6 +347,7 @@ class TestRDocRIStore < RDoc::TestCase
176
347
  assert_equal cache, @s.cache
177
348
 
178
349
  assert_equal :encoding_value, @s.encoding
350
+ assert_equal 'README.txt', @s.main
179
351
  end
180
352
 
181
353
  def test_load_cache_encoding_differs
@@ -183,8 +355,10 @@ class TestRDocRIStore < RDoc::TestCase
183
355
 
184
356
  cache = {
185
357
  :encoding => Encoding::ISO_8859_1,
186
- :methods => %w[Object#method],
358
+ :main => nil,
359
+ :methods => { "Object" => %w[Object#method] },
187
360
  :modules => %w[Object],
361
+ :pages => [],
188
362
  }
189
363
 
190
364
  Dir.mkdir @tmpdir
@@ -209,7 +383,10 @@ class TestRDocRIStore < RDoc::TestCase
209
383
  :class_methods => {},
210
384
  :encoding => nil,
211
385
  :instance_methods => {},
386
+ :main => nil,
212
387
  :modules => [],
388
+ :pages => [],
389
+ :title => nil,
213
390
  }
214
391
 
215
392
  @s.load_cache
@@ -217,17 +394,96 @@ class TestRDocRIStore < RDoc::TestCase
217
394
  assert_equal cache, @s.cache
218
395
  end
219
396
 
397
+ def test_load_cache_legacy
398
+ cache = {
399
+ :ancestors => {},
400
+ :attributes => {},
401
+ :class_methods => {},
402
+ :encoding => :encoding_value,
403
+ :instance_methods => { "Object" => %w[Object#method] },
404
+ :modules => %w[Object],
405
+ # no :pages
406
+ # no :main
407
+ }
408
+
409
+ Dir.mkdir @tmpdir
410
+
411
+ open File.join(@tmpdir, 'cache.ri'), 'wb' do |io|
412
+ Marshal.dump cache, io
413
+ end
414
+
415
+ @s.load_cache
416
+
417
+ expected = {
418
+ :ancestors => {},
419
+ :attributes => {},
420
+ :class_methods => {},
421
+ :encoding => :encoding_value,
422
+ :instance_methods => { "Object" => %w[Object#method] },
423
+ :main => nil,
424
+ :modules => %w[Object],
425
+ :pages => [],
426
+ }
427
+
428
+ assert_equal expected, @s.cache
429
+
430
+ assert_equal :encoding_value, @s.encoding
431
+ assert_nil @s.main
432
+ end
433
+
220
434
  def test_load_class
221
435
  @s.save_class @klass
436
+ @s.classes_hash.clear
222
437
 
223
438
  assert_equal @klass, @s.load_class('Object')
439
+
440
+ assert_includes @s.classes_hash, 'Object'
224
441
  end
225
442
 
226
- def test_load_method_bang
443
+ def test_load_method
227
444
  @s.save_method @klass, @meth_bang
228
445
 
229
446
  meth = @s.load_method('Object', '#method!')
230
447
  assert_equal @meth_bang, meth
448
+ assert_equal @klass, meth.parent
449
+ assert_equal @s, meth.store
450
+ end
451
+
452
+ def test_load_method_legacy
453
+ @s.save_method @klass, @meth
454
+
455
+ file = @s.method_file @klass.full_name, @meth.full_name
456
+
457
+ open file, 'wb' do |io|
458
+ io.write "\x04\bU:\x14RDoc::AnyMethod[\x0Fi\x00I" +
459
+ "\"\vmethod\x06:\x06EF\"\x11Klass#method0:\vpublic" +
460
+ "o:\eRDoc::Markup::Document\x06:\v@parts[\x06" +
461
+ "o:\x1CRDoc::Markup::Paragraph\x06;\t[\x06I" +
462
+ "\"\x16this is a comment\x06;\x06FI" +
463
+ "\"\rcall_seq\x06;\x06FI\"\x0Fsome_block\x06;\x06F" +
464
+ "[\x06[\aI\"\faliased\x06;\x06Fo;\b\x06;\t[\x06" +
465
+ "o;\n\x06;\t[\x06I\"\x12alias comment\x06;\x06FI" +
466
+ "\"\nparam\x06;\x06F"
467
+ end
468
+
469
+ meth = @s.load_method('Object', '#method')
470
+ assert_equal 'Klass#method', meth.full_name
471
+ assert_equal @klass, meth.parent
472
+ assert_equal @s, meth.store
473
+ end
474
+
475
+ def test_load_page
476
+ @s.save_page @page
477
+
478
+ assert_equal @page, @s.load_page('README.txt')
479
+ end
480
+
481
+ def test_main
482
+ assert_equal nil, @s.main
483
+
484
+ @s.main = 'README.txt'
485
+
486
+ assert_equal 'README.txt', @s.main
231
487
  end
232
488
 
233
489
  def test_method_file
@@ -244,29 +500,89 @@ class TestRDocRIStore < RDoc::TestCase
244
500
  @s.method_file('Object', 'Object::method')
245
501
  end
246
502
 
503
+ def test_module_names
504
+ @s.save_class @klass
505
+
506
+ assert_equal %w[Object], @s.module_names
507
+ end
508
+
509
+ def test_page
510
+ page = @store.add_file 'PAGE.txt'
511
+ page.parser = RDoc::Parser::Simple
512
+
513
+ assert_nil @store.page 'no such page'
514
+
515
+ assert_equal page, @store.page('PAGE')
516
+ end
517
+
518
+ def test_save
519
+ FileUtils.mkdir_p @tmpdir
520
+
521
+ @s.save
522
+
523
+ assert_directory File.join(@tmpdir, 'Object')
524
+
525
+ assert_file File.join(@tmpdir, 'Object', 'cdesc-Object.ri')
526
+ assert_file File.join(@tmpdir, 'Object', 'method-i.ri')
527
+ assert_file File.join(@tmpdir, 'page-README_txt.ri')
528
+
529
+ assert_file File.join(@tmpdir, 'cache.ri')
530
+
531
+ expected = {
532
+ :ancestors => {
533
+ 'Object::SubClass' => %w[Incl Object],
534
+ },
535
+ :attributes => { 'Object' => ['attr_accessor attr'] },
536
+ :class_methods => { 'Object' => %w[cmethod] },
537
+ :instance_methods => {
538
+ 'Object' => %w[attr method method! method_bang],
539
+ 'Object::SubClass' => %w[method],
540
+ },
541
+ :main => nil,
542
+ :modules => %w[Mod Object Object::SubClass],
543
+ :encoding => nil,
544
+ :pages => %w[README.txt],
545
+ :title => nil,
546
+ }
547
+
548
+ expected[:ancestors]['Object'] = %w[BasicObject] if defined?(::BasicObject)
549
+
550
+ open File.join(@tmpdir, 'cache.ri'), 'rb' do |io|
551
+ cache = Marshal.load io.read
552
+
553
+ assert_equal expected, cache
554
+ end
555
+ end
556
+
247
557
  def test_save_cache
248
558
  @s.save_class @klass
249
559
  @s.save_method @klass, @meth
250
560
  @s.save_method @klass, @cmeth
251
561
  @s.save_class @nest_klass
562
+ @s.save_page @page
252
563
  @s.encoding = :encoding_value
564
+ @s.main = @page.full_name
565
+ @s.title = 'title'
253
566
 
254
567
  @s.save_cache
255
568
 
256
569
  assert_file File.join(@tmpdir, 'cache.ri')
257
570
 
258
571
  expected = {
572
+ :ancestors => {
573
+ 'Object::SubClass' => %w[Incl Object],
574
+ },
259
575
  :attributes => { 'Object' => ['attr_accessor attr'] },
260
576
  :class_methods => { 'Object' => %w[cmethod] },
261
577
  :instance_methods => {
262
- 'Object' => %w[method method!],
578
+ 'Object' => %w[method method! method_bang],
263
579
  'Object::SubClass' => %w[method],
264
580
  },
581
+ :main => @page.full_name,
265
582
  :modules => %w[Object Object::SubClass],
266
- :ancestors => {
267
- 'Object::SubClass' => %w[Incl Object],
268
- },
269
583
  :encoding => :encoding_value,
584
+ :pages => %w[README.txt],
585
+ :title => 'title',
270
586
  }
271
587
 
272
588
  expected[:ancestors]['Object'] = %w[BasicObject] if defined?(::BasicObject)
@@ -300,6 +616,15 @@ class TestRDocRIStore < RDoc::TestCase
300
616
  assert_cache({ 'Object' => %w[method] }, {}, {}, [])
301
617
  end
302
618
 
619
+ def test_save_cache_duplicate_pages
620
+ @s.save_page @page
621
+ @s.save_page @page
622
+
623
+ @s.save_cache
624
+
625
+ assert_cache({}, {}, {}, [], {}, %w[README.txt])
626
+ end
627
+
303
628
  def test_save_class
304
629
  @s.save_class @klass
305
630
 
@@ -388,8 +713,10 @@ class TestRDocRIStore < RDoc::TestCase
388
713
 
389
714
  # This is a functional test
390
715
  def test_save_class_merge_constant
391
- tl = RDoc::TopLevel.new 'file.rb'
392
- klass = RDoc::NormalClass.new 'C'
716
+ store = RDoc::Store.new
717
+ tl = store.add_file 'file.rb'
718
+
719
+ klass = tl.add_class RDoc::NormalClass, 'C'
393
720
  klass.add_comment 'comment', tl
394
721
 
395
722
  const = klass.add_constant RDoc::Constant.new('CONST', nil, nil)
@@ -397,14 +724,16 @@ class TestRDocRIStore < RDoc::TestCase
397
724
 
398
725
  @s.save_class klass
399
726
 
400
- RDoc::RDoc.reset
401
-
402
- klass2 = RDoc::NormalClass.new 'C'
727
+ # separate parse run, independent store
728
+ store = RDoc::Store.new
729
+ tl = store.add_file 'file.rb'
730
+ klass2 = tl.add_class RDoc::NormalClass, 'C'
403
731
  klass2.record_location tl
404
732
 
405
733
  s = RDoc::RI::Store.new @tmpdir
406
734
  s.save_class klass2
407
735
 
736
+ # separate `ri` run, independent store
408
737
  s = RDoc::RI::Store.new @tmpdir
409
738
 
410
739
  result = s.load_class 'C'
@@ -462,5 +791,49 @@ class TestRDocRIStore < RDoc::TestCase
462
791
  assert_cache({ 'Object::SubClass' => %w[method] }, {}, {}, [])
463
792
  end
464
793
 
794
+ def test_save_page
795
+ @s.save_page @page
796
+
797
+ assert_file File.join(@tmpdir, 'page-README_txt.ri')
798
+
799
+ assert_cache({}, {}, {}, [], {}, %w[README.txt])
800
+ end
801
+
802
+ def test_save_page_file
803
+ @s.save_page @top_level
804
+
805
+ refute_file File.join(@tmpdir, 'page-file_rb.ri')
806
+ end
807
+
808
+ def test_source
809
+ @s.path = @tmpdir
810
+ @s.type = nil
811
+ assert_equal @s.path, @s.source
812
+
813
+ @s.type = :extra
814
+ assert_equal @s.path, @s.source
815
+
816
+ @s.type = :system
817
+ assert_equal "ruby", @s.source
818
+
819
+ @s.type = :site
820
+ assert_equal "site", @s.source
821
+
822
+ @s.type = :home
823
+ assert_equal "home", @s.source
824
+
825
+ @s.type = :gem
826
+ @s.path = "#{@tmpdir}/gem_repository/doc/gem_name-1.0/ri"
827
+ assert_equal "gem_name-1.0", @s.source
828
+ end
829
+
830
+ def test_title
831
+ assert_equal nil, @s.title
832
+
833
+ @s.title = 'rdoc'
834
+
835
+ assert_equal 'rdoc', @s.title
836
+ end
837
+
465
838
  end
466
839