rdoc 2.4.3 → 2.5

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 (139) hide show
  1. data.tar.gz.sig +0 -0
  2. data/.autotest +3 -1
  3. data/History.txt +68 -0
  4. data/LICENSE.txt +57 -0
  5. data/Manifest.txt +37 -19
  6. data/README.txt +2 -12
  7. data/Rakefile +12 -12
  8. data/bin/rdoc +4 -4
  9. data/lib/rdoc.rb +32 -9
  10. data/lib/rdoc/alias.rb +2 -2
  11. data/lib/rdoc/any_method.rb +108 -16
  12. data/lib/rdoc/attr.rb +87 -1
  13. data/lib/rdoc/class_module.rb +131 -5
  14. data/lib/rdoc/code_object.rb +28 -5
  15. data/lib/rdoc/constant.rb +22 -0
  16. data/lib/rdoc/context.rb +80 -37
  17. data/lib/rdoc/gauntlet.rb +48 -0
  18. data/lib/rdoc/generator/darkfish.rb +25 -23
  19. data/lib/rdoc/generator/markup.rb +6 -29
  20. data/lib/rdoc/generator/ri.rb +39 -189
  21. data/lib/rdoc/generator/template/darkfish/classpage.rhtml +17 -1
  22. data/lib/rdoc/generator/template/darkfish/filepage.rhtml +10 -0
  23. data/lib/rdoc/generator/template/darkfish/images/brick.png +0 -0
  24. data/lib/rdoc/generator/template/darkfish/images/brick_link.png +0 -0
  25. data/lib/rdoc/generator/template/darkfish/images/bullet_black.png +0 -0
  26. data/lib/rdoc/generator/template/darkfish/images/bullet_toggle_minus.png +0 -0
  27. data/lib/rdoc/generator/template/darkfish/images/bullet_toggle_plus.png +0 -0
  28. data/lib/rdoc/generator/template/darkfish/images/date.png +0 -0
  29. data/lib/rdoc/generator/template/darkfish/images/find.png +0 -0
  30. data/lib/rdoc/generator/template/darkfish/images/package.png +0 -0
  31. data/lib/rdoc/generator/template/darkfish/images/page_green.png +0 -0
  32. data/lib/rdoc/generator/template/darkfish/images/page_white_text.png +0 -0
  33. data/lib/rdoc/generator/template/darkfish/images/page_white_width.png +0 -0
  34. data/lib/rdoc/generator/template/darkfish/images/plugin.png +0 -0
  35. data/lib/rdoc/generator/template/darkfish/images/ruby.png +0 -0
  36. data/lib/rdoc/generator/template/darkfish/images/tag_green.png +0 -0
  37. data/lib/rdoc/generator/template/darkfish/images/wrench.png +0 -0
  38. data/lib/rdoc/generator/template/darkfish/images/wrench_orange.png +0 -0
  39. data/lib/rdoc/generator/template/darkfish/images/zoom.png +0 -0
  40. data/lib/rdoc/generator/template/darkfish/index.rhtml +2 -2
  41. data/lib/rdoc/generator/template/darkfish/rdoc.css +38 -33
  42. data/lib/rdoc/include.rb +22 -0
  43. data/lib/rdoc/markup.rb +10 -262
  44. data/lib/rdoc/markup/attribute_manager.rb +57 -50
  45. data/lib/rdoc/markup/blank_line.rb +19 -0
  46. data/lib/rdoc/markup/document.rb +72 -0
  47. data/lib/rdoc/markup/formatter.rb +118 -0
  48. data/lib/rdoc/markup/formatter_test_case.rb +341 -0
  49. data/lib/rdoc/markup/heading.rb +17 -0
  50. data/lib/rdoc/markup/inline.rb +6 -5
  51. data/lib/rdoc/markup/list.rb +78 -0
  52. data/lib/rdoc/markup/list_item.rb +83 -0
  53. data/lib/rdoc/markup/paragraph.rb +66 -0
  54. data/lib/rdoc/markup/parser.rb +528 -0
  55. data/lib/rdoc/markup/rule.rb +17 -0
  56. data/lib/rdoc/markup/to_ansi.rb +72 -0
  57. data/lib/rdoc/markup/to_bs.rb +74 -0
  58. data/lib/rdoc/markup/to_html.rb +106 -172
  59. data/lib/rdoc/markup/to_html_crossref.rb +10 -4
  60. data/lib/rdoc/markup/to_rdoc.rb +243 -0
  61. data/lib/rdoc/markup/to_test.rb +27 -16
  62. data/lib/rdoc/markup/verbatim.rb +42 -0
  63. data/lib/rdoc/normal_class.rb +38 -1
  64. data/lib/rdoc/normal_module.rb +38 -8
  65. data/lib/rdoc/options.rb +39 -151
  66. data/lib/rdoc/parser.rb +36 -18
  67. data/lib/rdoc/parser/c.rb +102 -109
  68. data/lib/rdoc/parser/ruby.rb +359 -1662
  69. data/lib/rdoc/parser/ruby_tools.rb +157 -0
  70. data/lib/rdoc/parser/simple.rb +0 -2
  71. data/lib/rdoc/rdoc.rb +142 -82
  72. data/lib/rdoc/ri.rb +10 -0
  73. data/lib/rdoc/ri/driver.rb +674 -444
  74. data/lib/rdoc/ri/formatter.rb +2 -651
  75. data/lib/rdoc/ri/paths.rb +70 -45
  76. data/lib/rdoc/ri/store.rb +248 -0
  77. data/lib/rdoc/ruby_lex.rb +1284 -0
  78. data/lib/rdoc/ruby_token.rb +416 -0
  79. data/lib/rdoc/single_class.rb +5 -0
  80. data/lib/rdoc/stats.rb +152 -83
  81. data/lib/rdoc/task.rb +27 -49
  82. data/lib/rdoc/text.rb +130 -0
  83. data/lib/rdoc/tokenstream.rb +28 -9
  84. data/lib/rdoc/top_level.rb +49 -43
  85. data/test/hidden.zip.txt +1 -0
  86. data/test/test_attribute_manager.rb +9 -16
  87. data/test/test_rdoc_any_method.rb +23 -0
  88. data/test/test_rdoc_attr.rb +40 -0
  89. data/test/test_rdoc_class_module.rb +100 -0
  90. data/test/test_rdoc_code_object.rb +18 -2
  91. data/test/test_rdoc_context.rb +41 -0
  92. data/test/test_rdoc_generator_ri.rb +56 -0
  93. data/test/test_rdoc_markup.rb +21 -610
  94. data/test/test_rdoc_markup_attribute_manager.rb +14 -17
  95. data/test/test_rdoc_markup_document.rb +51 -0
  96. data/test/test_rdoc_markup_paragraph.rb +27 -0
  97. data/test/test_rdoc_markup_parser.rb +1327 -0
  98. data/test/test_rdoc_markup_to_ansi.rb +426 -0
  99. data/test/test_rdoc_markup_to_bs.rb +443 -0
  100. data/test/test_rdoc_markup_to_html.rb +183 -18
  101. data/test/test_rdoc_markup_to_html_crossref.rb +1 -3
  102. data/test/test_rdoc_markup_to_rdoc.rb +426 -0
  103. data/test/test_rdoc_normal_class.rb +17 -0
  104. data/test/test_rdoc_normal_module.rb +6 -6
  105. data/test/test_rdoc_options.rb +41 -0
  106. data/test/test_rdoc_parser.rb +66 -13
  107. data/test/test_rdoc_parser_c.rb +93 -38
  108. data/test/test_rdoc_parser_perl.rb +2 -3
  109. data/test/test_rdoc_parser_ruby.rb +291 -28
  110. data/test/test_rdoc_parser_simple.rb +48 -0
  111. data/test/test_rdoc_rdoc.rb +66 -0
  112. data/test/test_rdoc_ri_driver.rb +752 -38
  113. data/test/test_rdoc_ri_paths.rb +39 -0
  114. data/test/test_rdoc_ri_store.rb +309 -0
  115. data/test/test_rdoc_text.rb +157 -0
  116. data/test/test_rdoc_top_level.rb +35 -9
  117. data/test/xref_data.rb +9 -1
  118. data/test/xref_test_case.rb +8 -3
  119. metadata +110 -38
  120. metadata.gz.sig +0 -0
  121. data/lib/rdoc/cache.rb +0 -41
  122. data/lib/rdoc/diagram.rb +0 -340
  123. data/lib/rdoc/dot.rb +0 -249
  124. data/lib/rdoc/markup/fragments.rb +0 -377
  125. data/lib/rdoc/markup/lines.rb +0 -156
  126. data/lib/rdoc/markup/to_flow.rb +0 -211
  127. data/lib/rdoc/markup/to_latex.rb +0 -328
  128. data/lib/rdoc/markup/to_texinfo.rb +0 -73
  129. data/lib/rdoc/ri/cache.rb +0 -187
  130. data/lib/rdoc/ri/descriptions.rb +0 -156
  131. data/lib/rdoc/ri/display.rb +0 -340
  132. data/lib/rdoc/ri/reader.rb +0 -106
  133. data/lib/rdoc/ri/util.rb +0 -79
  134. data/lib/rdoc/ri/writer.rb +0 -68
  135. data/test/test_rdoc_ri_attribute_formatter.rb +0 -44
  136. data/test/test_rdoc_ri_default_display.rb +0 -302
  137. data/test/test_rdoc_ri_formatter.rb +0 -320
  138. data/test/test_rdoc_ri_html_formatter.rb +0 -141
  139. data/test/test_rdoc_ri_overstrike_formatter.rb +0 -71
@@ -0,0 +1,48 @@
1
+ require 'tempfile'
2
+ require 'rubygems'
3
+ require 'minitest/autorun'
4
+ require 'rdoc/options'
5
+ require 'rdoc/parser'
6
+
7
+ class TestRDocParserSimple < MiniTest::Unit::TestCase
8
+
9
+ def setup
10
+ @tempfile = Tempfile.new self.class.name
11
+ filename = @tempfile.path
12
+
13
+ @top_level = RDoc::TopLevel.new filename
14
+ @fn = filename
15
+ @options = RDoc::Options.new
16
+ @stats = RDoc::Stats.new 0
17
+
18
+ RDoc::TopLevel.reset
19
+ end
20
+
21
+ def teardown
22
+ @tempfile.close
23
+ end
24
+
25
+ def test_remove_private_comments
26
+ parser = util_parser ''
27
+ text = "foo\n\n--\nbar\n++\n\nbaz\n"
28
+
29
+ expected = "foo\n\n\n\nbaz\n"
30
+
31
+ assert_equal expected, parser.remove_private_comments(text)
32
+ end
33
+
34
+ def test_remove_private_comments_star
35
+ parser = util_parser ''
36
+
37
+ text = "* foo\n* bar\n"
38
+ expected = text.dup
39
+
40
+ assert_equal expected, parser.remove_private_comments(text)
41
+ end
42
+
43
+ def util_parser(content)
44
+ RDoc::Parser::Simple.new @top_level, @fn, content, @options, @stats
45
+ end
46
+
47
+ end
48
+
@@ -0,0 +1,66 @@
1
+ require 'tempfile'
2
+ require 'rubygems'
3
+ require 'minitest/autorun'
4
+ require 'rdoc/rdoc'
5
+
6
+ class TestRDocRDoc < MiniTest::Unit::TestCase
7
+
8
+ def setup
9
+ @rdoc = RDoc::RDoc.new
10
+ @tempfile = Tempfile.new 'test_rdoc_rdoc'
11
+ end
12
+
13
+ def teardown
14
+ @tempfile.close
15
+ end
16
+
17
+ def test_gather_files
18
+ assert_equal(%w[lib/rdoc.rb],
19
+ @rdoc.gather_files(%w[lib/rdoc.rb lib/rdoc.rb]))
20
+ end
21
+
22
+ def test_read_file_contents
23
+ @tempfile.write "hi everybody"
24
+ @tempfile.flush
25
+
26
+ assert_equal "hi everybody", @rdoc.read_file_contents(@tempfile.path)
27
+ end
28
+
29
+ def test_read_file_contents_encoding
30
+ skip "Encoding not implemented" unless defined? ::Encoding
31
+
32
+ @tempfile.write "# coding: utf-8\nhi everybody"
33
+ @tempfile.flush
34
+
35
+ contents = @rdoc.read_file_contents @tempfile.path
36
+ assert_equal "# coding: utf-8\nhi everybody", contents
37
+ assert_equal Encoding::UTF_8, contents.encoding
38
+ end
39
+
40
+ def test_read_file_contents_encoding_fancy
41
+ skip "Encoding not implemented" unless defined? ::Encoding
42
+
43
+ @tempfile.write "# -*- coding: utf-8; fill-column: 74 -*-\nhi everybody"
44
+ @tempfile.flush
45
+
46
+ contents = @rdoc.read_file_contents @tempfile.path
47
+ assert_equal("# -*- coding: utf-8; fill-column: 74 -*-\nhi everybody",
48
+ contents)
49
+ assert_equal Encoding::UTF_8, contents.encoding
50
+ end
51
+
52
+ def test_remove_unparsable
53
+ file_list = %w[
54
+ blah.class
55
+ blah.eps
56
+ blah.erb
57
+ blah.scpt.txt
58
+ blah.ttf
59
+ blah.yml
60
+ ]
61
+
62
+ assert_empty @rdoc.remove_unparseable file_list
63
+ end
64
+
65
+ end
66
+
@@ -1,94 +1,808 @@
1
+ require 'pp'
1
2
  require 'rubygems'
2
- require 'minitest/unit'
3
+ require 'minitest/autorun'
3
4
  require 'tmpdir'
5
+ require 'fileutils'
4
6
  require 'rdoc/ri/driver'
5
7
 
6
8
  class TestRDocRIDriver < MiniTest::Unit::TestCase
7
9
 
8
10
  def setup
11
+ @RM = RDoc::Markup
12
+
9
13
  @tmpdir = File.join Dir.tmpdir, "test_rdoc_ri_driver_#{$$}"
10
14
  @home_ri = File.join @tmpdir, 'dot_ri'
11
- @cache_dir = File.join @home_ri, 'cache'
12
- @class_cache = File.join @cache_dir, 'classes'
13
15
 
14
16
  FileUtils.mkdir_p @tmpdir
15
17
  FileUtils.mkdir_p @home_ri
16
- FileUtils.mkdir_p @cache_dir
17
18
 
18
- @driver = RDoc::RI::Driver.new(RDoc::RI::Driver.process_args([]))
19
- @driver.homepath = @home_ri
19
+ @orig_ri = ENV['RI']
20
+ @orig_home = ENV['HOME']
21
+ ENV['HOME'] = @tmpdir
22
+ ENV.delete 'RI'
23
+
24
+ options = RDoc::RI::Driver.process_args []
25
+ options[:home] = @tmpdir
26
+ options[:use_stdout] = true
27
+ options[:formatter] = @RM::ToRdoc
28
+ @driver = RDoc::RI::Driver.new options
20
29
  end
21
30
 
22
31
  def teardown
32
+ ENV['HOME'] = @orig_home
33
+ ENV['RI'] = @orig_ri
23
34
  FileUtils.rm_rf @tmpdir
24
35
  end
25
36
 
26
- def test_lookup_method
27
- def @driver.load_cache_for(klassname)
28
- { 'Foo#bar' => :found }
37
+ def mu_pp(obj)
38
+ s = ''
39
+ s = PP.pp obj, s
40
+ s = s.force_encoding(Encoding.default_external) if defined? Encoding
41
+ s.chomp
42
+ end
43
+
44
+ def test_self_dump
45
+ util_store
46
+
47
+ out, err = capture_io do
48
+ RDoc::RI::Driver.dump @store.cache_path
29
49
  end
30
50
 
31
- assert @driver.lookup_method('Foo#bar', 'Foo')
51
+ assert_match %r%:class_methods%, out
52
+ assert_match %r%:modules%, out
53
+ assert_match %r%:instance_methods%, out
54
+ assert_match %r%:ancestors%, out
55
+ end
56
+
57
+ def test_add_also_in_empty
58
+ out = @RM::Document.new
59
+
60
+ @driver.add_also_in out, []
61
+
62
+ assert_empty out
63
+ end
64
+
65
+ def test_add_also_in
66
+ util_multi_store
67
+ @store1.type = :system
68
+ @store2.type = :home
69
+
70
+ out = @RM::Document.new
71
+
72
+ @driver.add_also_in out, [@store1, @store2]
73
+
74
+ expected = @RM::Document.new(
75
+ @RM::Rule.new(1),
76
+ @RM::Paragraph.new('Also found in:'),
77
+ @RM::Verbatim.new(' ', 'ruby core', "\n",
78
+ ' ', '~/.ri', "\n"))
79
+
80
+ assert_equal expected, out
81
+ end
82
+
83
+ def test_add_class
84
+ util_multi_store
85
+
86
+ out = @RM::Document.new
87
+
88
+ @driver.add_class out, 'Bar', [@cBar]
89
+
90
+ expected = @RM::Document.new(
91
+ @RM::Heading.new(1, 'Bar < Foo'),
92
+ @RM::BlankLine.new)
93
+
94
+ assert_equal expected, out
95
+ end
96
+
97
+ def test_add_from
98
+ util_store
99
+ @store.type = :system
100
+
101
+ out = @RM::Document.new
102
+
103
+ @driver.add_from out, @store
104
+
105
+ expected = @RM::Document.new @RM::Paragraph.new("(from ruby core)")
106
+
107
+ assert_equal expected, out
108
+ end
109
+
110
+ def test_add_includes_empty
111
+ out = @RM::Document.new
112
+
113
+ @driver.add_includes out, []
114
+
115
+ assert_empty out
116
+ end
117
+
118
+ def test_add_includes_many
119
+ util_store
120
+
121
+ out = @RM::Document.new
122
+
123
+ enum = RDoc::Include.new 'Enumerable', nil
124
+ @cFoo.add_include enum
125
+
126
+ @driver.add_includes out, [[[@cFooInc, enum], @store]]
127
+
128
+ expected = @RM::Document.new(
129
+ @RM::Rule.new(1),
130
+ @RM::Heading.new(1, "Includes:"),
131
+ @RM::Paragraph.new("(from #{@store.friendly_path})"),
132
+ @RM::BlankLine.new,
133
+ @RM::Paragraph.new("Inc"),
134
+ @RM::BlankLine.new,
135
+ @RM::Paragraph.new("Include thingy"),
136
+ @RM::BlankLine.new,
137
+ @RM::Verbatim.new(' ', 'Enumerable', "\n"))
138
+
139
+ assert_equal expected, out
32
140
  end
33
141
 
34
- def test_lookup_method_class_method
35
- def @driver.load_cache_for(klassname)
36
- { 'Foo::Bar' => :found }
142
+ def test_add_includes_many_no_doc
143
+ util_store
144
+
145
+ out = @RM::Document.new
146
+
147
+ enum = RDoc::Include.new 'Enumerable', nil
148
+ @cFoo.add_include enum
149
+ @cFooInc.instance_variable_set :@comment, ''
150
+
151
+ @driver.add_includes out, [[[@cFooInc, enum], @store]]
152
+
153
+ expected = @RM::Document.new(
154
+ @RM::Rule.new(1),
155
+ @RM::Heading.new(1, "Includes:"),
156
+ @RM::Paragraph.new("(from #{@store.friendly_path})"),
157
+ @RM::Verbatim.new(' ', 'Inc', "\n",
158
+ ' ', 'Enumerable', "\n"))
159
+
160
+ assert_equal expected, out
161
+ end
162
+
163
+ def test_add_includes_one
164
+ util_store
165
+
166
+ out = @RM::Document.new
167
+
168
+ @driver.add_includes out, [[[@cFooInc], @store]]
169
+
170
+ expected = @RM::Document.new(
171
+ @RM::Rule.new(1),
172
+ @RM::Heading.new(1, "Includes:"),
173
+ @RM::Paragraph.new("Inc (from #{@store.friendly_path})"),
174
+ @RM::BlankLine.new,
175
+ @RM::Paragraph.new("Include thingy"),
176
+ @RM::BlankLine.new)
177
+
178
+ assert_equal expected, out
179
+ end
180
+
181
+ def test_add_method_list
182
+ out = @RM::Document.new
183
+
184
+ @driver.add_method_list out, %w[new], 'Class methods'
185
+
186
+ expected = @RM::Document.new(
187
+ @RM::Heading.new(1, 'Class methods:'),
188
+ @RM::BlankLine.new,
189
+ @RM::Verbatim.new(' ', 'new'),
190
+ @RM::BlankLine.new)
191
+
192
+ assert_equal expected, out
193
+ end
194
+
195
+ def test_add_method_list_none
196
+ out = @RM::Document.new
197
+
198
+ @driver.add_method_list out, nil, 'Class'
199
+
200
+ assert_equal @RM::Document.new, out
201
+ end
202
+
203
+ def test_ancestors_of
204
+ util_ancestors_store
205
+
206
+ assert_equal %w[X Mixin Object Foo], @driver.ancestors_of('Foo::Bar')
207
+ end
208
+
209
+ def test_classes
210
+ util_multi_store
211
+
212
+ expected = {
213
+ 'Ambiguous' => [@store1, @store2],
214
+ 'Bar' => [@store2],
215
+ 'Foo' => [@store1],
216
+ 'Foo::Bar' => [@store1],
217
+ 'Foo::Baz' => [@store1, @store2],
218
+ 'Inc' => [@store1],
219
+ }
220
+
221
+ assert_equal expected, @driver.classes
222
+ end
223
+
224
+ def test_complete
225
+ store = RDoc::RI::Store.new @home_ri
226
+ store.cache[:ancestors] = {
227
+ 'Foo' => %w[Object],
228
+ 'Foo::Bar' => %w[Object],
229
+ }
230
+ store.cache[:class_methods] = {
231
+ 'Foo' => %w[bar]
232
+ }
233
+ store.cache[:instance_methods] = {
234
+ 'Foo' => %w[Bar]
235
+ }
236
+ store.cache[:modules] = %w[
237
+ Foo
238
+ Foo::Bar
239
+ ]
240
+
241
+ @driver.stores = [store]
242
+
243
+ assert_equal %w[Foo Foo::Bar], @driver.complete('F')
244
+ assert_equal %w[ Foo::Bar], @driver.complete('Foo::B')
245
+
246
+ assert_equal %w[Foo#Bar], @driver.complete('Foo#'), 'Foo#'
247
+ assert_equal %w[Foo#Bar Foo::bar], @driver.complete('Foo.'), 'Foo.'
248
+ assert_equal %w[Foo::Bar Foo::bar], @driver.complete('Foo::'), 'Foo::'
249
+ end
250
+
251
+ def test_complete_ancestor
252
+ util_ancestors_store
253
+
254
+ assert_equal %w[Foo::Bar#i_method], @driver.complete('Foo::Bar#')
255
+
256
+ assert_equal %w[Foo::Bar#i_method Foo::Bar::c_method Foo::Bar::new],
257
+ @driver.complete('Foo::Bar.')
258
+ end
259
+
260
+ def test_complete_classes
261
+ util_store
262
+
263
+ assert_equal %w[Foo Foo::Bar Foo::Baz], @driver.complete('F')
264
+ assert_equal %w[Foo:: Foo::Bar Foo::Baz], @driver.complete('Foo::')
265
+ assert_equal %w[ Foo::Bar Foo::Baz], @driver.complete('Foo::B')
266
+ end
267
+
268
+ def test_complete_multistore
269
+ util_multi_store
270
+
271
+ assert_equal %w[Bar], @driver.complete('B')
272
+ assert_equal %w[Foo Foo::Bar Foo::Baz], @driver.complete('F')
273
+ end
274
+
275
+ def test_display
276
+ doc = @RM::Document.new(
277
+ @RM::Paragraph.new('hi'))
278
+
279
+ out, err = capture_io do
280
+ @driver.display doc
37
281
  end
38
282
 
39
- assert @driver.lookup_method('Foo::Bar', 'Foo::Bar')
283
+ assert_equal "hi\n", out
40
284
  end
41
285
 
42
- def test_lookup_method_class_missing
43
- def @driver.load_cache_for(klassname) end
286
+ def test_display_class
287
+ util_store
44
288
 
45
- assert_nil @driver.lookup_method('Foo#bar', 'Foo')
289
+ out, err = capture_io do
290
+ @driver.display_class 'Foo::Bar'
291
+ end
292
+
293
+ assert_match %r%^= Foo::Bar%, out
294
+ assert_match %r%^\(from%, out # )
295
+
296
+ assert_match %r%^= Class methods:%, out
297
+ assert_match %r%^ new%, out
298
+ assert_match %r%^= Instance methods:%, out
299
+ assert_match %r%^ blah%, out
300
+ assert_match %r%^= Attributes:%, out
301
+ assert_match %r%^ attr_accessor attr%, out
302
+
303
+ assert_equal 1, out.scan(/-\n/).length
46
304
  end
47
305
 
48
- def test_lookup_method_dot_instance
49
- def @driver.load_cache_for(klassname)
50
- { 'Foo#bar' => :instance, 'Foo::bar' => :klass }
306
+ def test_display_class_ambiguous
307
+ util_multi_store
308
+
309
+ out, err = capture_io do
310
+ @driver.display_class 'Ambiguous'
51
311
  end
52
312
 
53
- assert_equal :instance, @driver.lookup_method('Foo.bar', 'Foo')
313
+ assert_match %r%^= Ambiguous < Object$%, out
54
314
  end
55
315
 
56
- def test_lookup_method_dot_class
57
- def @driver.load_cache_for(klassname)
58
- { 'Foo::bar' => :found }
316
+ def test_display_class_multi_no_doc
317
+ util_multi_store
318
+
319
+ out, err = capture_io do
320
+ @driver.display_class 'Foo::Baz'
59
321
  end
60
322
 
61
- assert @driver.lookup_method('Foo.bar', 'Foo')
323
+ assert_match %r%^= Foo::Baz%, out
324
+ assert_match %r%-\n%, out
325
+ assert_match %r%Also found in:%, out
326
+ assert_match %r%#{Regexp.escape @home_ri}%, out
327
+ assert_match %r%#{Regexp.escape @home_ri2}%, out
62
328
  end
63
329
 
64
- def test_lookup_method_method_missing
65
- def @driver.load_cache_for(klassname) {} end
330
+ def test_display_class_superclass
331
+ util_multi_store
332
+
333
+ out, err = capture_io do
334
+ @driver.display_class 'Bar'
335
+ end
66
336
 
67
- assert_nil @driver.lookup_method('Foo#bar', 'Foo')
337
+ assert_match %r%^= Bar < Foo%, out
68
338
  end
69
339
 
70
- def test_parse_name
71
- klass, meth = @driver.parse_name 'Foo::Bar'
340
+ def test_display_class_module
341
+ util_store
72
342
 
73
- assert_equal 'Foo::Bar', klass, 'Foo::Bar class'
74
- assert_equal nil, meth, 'Foo::Bar method'
343
+ out, err = capture_io do
344
+ @driver.display_class 'Inc'
345
+ end
346
+
347
+ assert_match %r%^= Inc$%, out
348
+ end
75
349
 
76
- klass, meth = @driver.parse_name 'Foo#Bar'
350
+ def test_display_method
351
+ util_store
77
352
 
78
- assert_equal 'Foo', klass, 'Foo#Bar class'
79
- assert_equal 'Bar', meth, 'Foo#Bar method'
353
+ out, err = capture_io do
354
+ @driver.display_method 'Foo::Bar#blah'
355
+ end
356
+
357
+ assert_match %r%Foo::Bar#blah%, out
358
+ assert_match %r%blah.5%, out
359
+ assert_match %r%blah.6%, out
360
+ assert_match %r%yields: stuff%, out
361
+ end
362
+
363
+ def test_display_method_attribute
364
+ util_store
365
+
366
+ out, err = capture_io do
367
+ @driver.display_method 'Foo::Bar#attr'
368
+ end
369
+
370
+ assert_match %r%Foo::Bar#attr%, out
371
+ refute_match %r%Implementation from%, out
372
+ end
373
+
374
+ def test_display_method_inherited
375
+ util_multi_store
376
+
377
+ out, err = capture_io do
378
+ @driver.display_method 'Bar#inherit'
379
+ end
380
+
381
+ assert_match %r%^= Bar#inherit%, out
382
+ assert_match %r%^=== Implementation from Foo%, out
383
+ end
384
+
385
+ def test_display_name_not_found_class
386
+ util_store
387
+
388
+ out, err = capture_io do
389
+ assert_equal false, @driver.display_name('Foo::B')
390
+ end
391
+
392
+ expected = <<-EXPECTED
393
+ Foo::B not found, maybe you meant:
394
+
395
+ Foo::Bar
396
+ Foo::Baz
397
+ EXPECTED
398
+
399
+ assert_equal expected, out
400
+ end
401
+
402
+ def test_display_name_not_found_method
403
+ util_store
404
+
405
+ out, err = capture_io do
406
+ assert_equal false, @driver.display_name('Foo::Bar#b')
407
+ end
408
+
409
+ expected = <<-EXPECTED
410
+ Foo::Bar#b not found, maybe you meant:
411
+
412
+ Foo::Bar#blah
413
+ Foo::Bar#bother
414
+ EXPECTED
415
+
416
+ assert_equal expected, out
417
+ end
418
+
419
+ def test_expand_class
420
+ util_store
421
+
422
+ assert_equal 'Foo', @driver.expand_class('F')
423
+ assert_equal 'Foo::Bar', @driver.expand_class('F::Bar')
424
+
425
+ assert_raises RDoc::RI::Driver::NotFoundError do
426
+ @driver.expand_class 'F::B'
427
+ end
428
+ end
429
+
430
+ def test_expand_name
431
+ util_store
80
432
 
81
- klass, meth = @driver.parse_name 'Foo.Bar'
433
+ assert_equal '.b', @driver.expand_name('b')
434
+ assert_equal 'Foo', @driver.expand_name('F')
435
+ assert_equal 'Foo::Bar#', @driver.expand_name('F::Bar#')
436
+
437
+ e = assert_raises RDoc::RI::Driver::NotFoundError do
438
+ @driver.expand_name 'Z'
439
+ end
440
+
441
+ assert_equal 'Z', e.name
442
+ end
443
+
444
+ def test_find_methods
445
+ util_store
446
+
447
+ items = []
448
+
449
+ @driver.find_methods 'Foo::Bar.' do |store, klass, ancestor, types, method|
450
+ items << [store, klass, ancestor, types, method]
451
+ end
452
+
453
+ expected = [
454
+ [@store, 'Foo::Bar', 'Foo::Bar', :both, nil],
455
+ ]
456
+
457
+ assert_equal expected, items
458
+ end
459
+
460
+ def test_find_methods_method
461
+ util_store
462
+
463
+ items = []
464
+
465
+ @driver.find_methods '.blah' do |store, klass, ancestor, types, method|
466
+ items << [store, klass, ancestor, types, method]
467
+ end
468
+
469
+ expected = [
470
+ [@store, 'Ambiguous', 'Ambiguous', :both, 'blah'],
471
+ [@store, 'Foo', 'Foo', :both, 'blah'],
472
+ [@store, 'Foo::Bar', 'Foo::Bar', :both, 'blah'],
473
+ [@store, 'Foo::Baz', 'Foo::Baz', :both, 'blah'],
474
+ [@store, 'Inc', 'Inc', :both, 'blah'],
475
+ ]
476
+
477
+ assert_equal expected, items
478
+ end
479
+
480
+ def test_formatter
481
+ driver = RDoc::RI::Driver.new
482
+
483
+ assert_instance_of @RM::ToAnsi, driver.formatter
484
+
485
+ driver.instance_variable_set :@paging, true
486
+
487
+ assert_instance_of @RM::ToBs, driver.formatter
488
+
489
+ driver.instance_variable_set :@formatter_klass, @RM::ToHtml
490
+
491
+ assert_instance_of @RM::ToHtml, driver.formatter
492
+ end
493
+
494
+ def test_method_type
495
+ assert_equal :both, @driver.method_type(nil)
496
+ assert_equal :both, @driver.method_type('.')
497
+ assert_equal :instance, @driver.method_type('#')
498
+ assert_equal :class, @driver.method_type('::')
499
+ end
500
+
501
+ def test_list_known_classes
502
+ util_store
503
+
504
+ out, err = capture_io do
505
+ @driver.list_known_classes
506
+ end
507
+
508
+ assert_equal "Ambiguous\nFoo\nFoo::Bar\nFoo::Baz\nInc\n", out
509
+ end
510
+
511
+ def test_list_methods_matching
512
+ util_store
513
+
514
+ assert_equal %w[Foo::Bar#attr Foo::Bar#blah Foo::Bar#bother Foo::Bar::new],
515
+ @driver.list_methods_matching('Foo::Bar.')
516
+ end
517
+
518
+ def test_load_method
519
+ util_store
520
+
521
+ method = @driver.load_method(@store, :instance_methods, 'Foo', '#',
522
+ 'inherit')
523
+
524
+ assert_equal @inherit, method
525
+ end
526
+
527
+ def test_load_method_inherited
528
+ util_multi_store
529
+
530
+ method = @driver.load_method(@store2, :instance_methods, 'Bar', '#',
531
+ 'inherit')
532
+
533
+ assert_equal nil, method
534
+ end
535
+
536
+ def test_load_methods_matching
537
+ util_store
538
+
539
+ expected = [[@store, [@inherit]]]
540
+
541
+ assert_equal expected, @driver.load_methods_matching('Foo#inherit')
542
+
543
+ expected = [[@store, [@blah]]]
544
+
545
+ assert_equal expected, @driver.load_methods_matching('.blah')
546
+
547
+ assert_empty @driver.load_methods_matching('.b')
548
+ end
549
+
550
+ def test_load_methods_matching_inherited
551
+ util_multi_store
552
+
553
+ expected = [[@store1, [@inherit]]]
554
+
555
+ assert_equal expected, @driver.load_methods_matching('Bar#inherit')
556
+ end
557
+
558
+ def test_page
559
+ @driver.use_stdout = false
560
+
561
+ @driver.page do |io|
562
+ skip "couldn't find a standard pager" if io == $stdout
563
+
564
+ assert @driver.paging?
565
+ end
566
+
567
+ refute @driver.paging?
568
+ end
569
+
570
+ def test_page_stdout
571
+ @driver.use_stdout = true
572
+
573
+ @driver.page do |io|
574
+ assert_equal $stdout, io
575
+ end
576
+
577
+ refute @driver.paging?
578
+ end
579
+
580
+ def test_parse_name_method
581
+ klass, type, meth = @driver.parse_name 'foo'
582
+
583
+ assert_equal '', klass, 'foo class'
584
+ assert_equal '.', type, 'foo type'
585
+ assert_equal 'foo', meth, 'foo method'
586
+
587
+ klass, type, meth = @driver.parse_name '#foo'
588
+
589
+ assert_equal '', klass, '#foo class'
590
+ assert_equal '#', type, '#foo type'
591
+ assert_equal 'foo', meth, '#foo method'
592
+
593
+ klass, type, meth = @driver.parse_name '::foo'
594
+
595
+ assert_equal '', klass, '::foo class'
596
+ assert_equal '::', type, '::foo type'
597
+ assert_equal 'foo', meth, '::foo method'
598
+ end
599
+
600
+ def test_parse_name_single_class
601
+ klass, type, meth = @driver.parse_name 'Foo'
602
+
603
+ assert_equal 'Foo', klass, 'Foo class'
604
+ assert_equal nil, type, 'Foo type'
605
+ assert_equal nil, meth, 'Foo method'
606
+
607
+ klass, type, meth = @driver.parse_name 'Foo#'
608
+
609
+ assert_equal 'Foo', klass, 'Foo# class'
610
+ assert_equal '#', type, 'Foo# type'
611
+ assert_equal nil, meth, 'Foo# method'
612
+
613
+ klass, type, meth = @driver.parse_name 'Foo::'
614
+
615
+ assert_equal 'Foo', klass, 'Foo:: class'
616
+ assert_equal '::', type, 'Foo:: type'
617
+ assert_equal nil, meth, 'Foo:: method'
618
+
619
+ klass, type, meth = @driver.parse_name 'Foo.'
620
+
621
+ assert_equal 'Foo', klass, 'Foo. class'
622
+ assert_equal '.', type, 'Foo. type'
623
+ assert_equal nil, meth, 'Foo. method'
624
+
625
+ klass, type, meth = @driver.parse_name 'Foo#Bar'
82
626
 
83
627
  assert_equal 'Foo', klass, 'Foo#Bar class'
628
+ assert_equal '#', type, 'Foo#Bar type'
84
629
  assert_equal 'Bar', meth, 'Foo#Bar method'
85
630
 
86
- klass, meth = @driver.parse_name 'Foo::bar'
631
+ klass, type, meth = @driver.parse_name 'Foo.Bar'
632
+
633
+ assert_equal 'Foo', klass, 'Foo.Bar class'
634
+ assert_equal '.', type, 'Foo.Bar type'
635
+ assert_equal 'Bar', meth, 'Foo.Bar method'
636
+
637
+ klass, type, meth = @driver.parse_name 'Foo::bar'
87
638
 
88
639
  assert_equal 'Foo', klass, 'Foo::bar class'
640
+ assert_equal '::', type, 'Foo::bar type'
89
641
  assert_equal 'bar', meth, 'Foo::bar method'
90
642
  end
91
643
 
644
+ def test_parse_name_namespace
645
+ klass, type, meth = @driver.parse_name 'Foo::Bar'
646
+
647
+ assert_equal 'Foo::Bar', klass, 'Foo::Bar class'
648
+ assert_equal nil, type, 'Foo::Bar type'
649
+ assert_equal nil, meth, 'Foo::Bar method'
650
+
651
+ klass, type, meth = @driver.parse_name 'Foo::Bar#'
652
+
653
+ assert_equal 'Foo::Bar', klass, 'Foo::Bar# class'
654
+ assert_equal '#', type, 'Foo::Bar# type'
655
+ assert_equal nil, meth, 'Foo::Bar# method'
656
+
657
+ klass, type, meth = @driver.parse_name 'Foo::Bar#baz'
658
+
659
+ assert_equal 'Foo::Bar', klass, 'Foo::Bar#baz class'
660
+ assert_equal '#', type, 'Foo::Bar#baz type'
661
+ assert_equal 'baz', meth, 'Foo::Bar#baz method'
662
+ end
663
+
664
+ def test_setup_pager
665
+ @driver.use_stdout = false
666
+
667
+ pager = @driver.setup_pager
668
+
669
+ skip "couldn't find a standard pager" unless pager
670
+
671
+ assert @driver.paging?
672
+ ensure
673
+ pager.close if pager
674
+ end
675
+
676
+ def util_ancestors_store
677
+ store1 = RDoc::RI::Store.new @home_ri
678
+ store1.cache[:ancestors] = {
679
+ 'Foo' => %w[Object],
680
+ 'Foo::Bar' => %w[Foo],
681
+ }
682
+ store1.cache[:class_methods] = {
683
+ 'Foo' => %w[c_method new],
684
+ 'Foo::Bar' => %w[new],
685
+ }
686
+ store1.cache[:instance_methods] = {
687
+ 'Foo' => %w[i_method],
688
+ }
689
+ store1.cache[:modules] = %w[
690
+ Foo
691
+ Foo::Bar
692
+ ]
693
+
694
+ store2 = RDoc::RI::Store.new @home_ri
695
+ store2.cache[:ancestors] = {
696
+ 'Foo' => %w[Mixin Object],
697
+ 'Mixin' => %w[],
698
+ 'Object' => %w[X Object],
699
+ 'X' => %w[Object],
700
+ }
701
+ store2.cache[:class_methods] = {
702
+ 'Foo' => %w[c_method new],
703
+ 'Mixin' => %w[],
704
+ 'X' => %w[],
705
+ 'Object' => %w[],
706
+ }
707
+ store2.cache[:instance_methods] = {
708
+ 'Foo' => %w[i_method],
709
+ 'Mixin' => %w[],
710
+ }
711
+ store2.cache[:modules] = %w[
712
+ Foo
713
+ Mixin
714
+ Object
715
+ X
716
+ ]
717
+
718
+ @driver.stores = store1, store2
719
+ end
720
+
721
+ def util_multi_store
722
+ util_store
723
+ @store1 = @store
724
+
725
+ @home_ri2 = "#{@home_ri}2"
726
+ @store2 = RDoc::RI::Store.new @home_ri2
727
+
728
+ # as if seen in a namespace like class Ambiguous::Other
729
+ @mAmbiguous = RDoc::NormalModule.new 'Ambiguous'
730
+
731
+ @cFoo = RDoc::NormalClass.new 'Foo'
732
+ @cBar = RDoc::NormalClass.new 'Bar'
733
+ @cBar.superclass = 'Foo'
734
+ @cFoo_Baz = RDoc::NormalClass.new 'Baz'
735
+ @cFoo_Baz.parent = @cFoo
736
+
737
+ @baz = RDoc::AnyMethod.new nil, 'baz'
738
+ @cBar.add_method @baz
739
+
740
+ @store2.save_class @mAmbiguous
741
+ @store2.save_class @cBar
742
+ @store2.save_class @cFoo_Baz
743
+
744
+ @store2.save_method @cBar, @baz
745
+
746
+ @store2.save_cache
747
+
748
+ @driver.stores = [@store1, @store2]
749
+ end
750
+
751
+ def util_store
752
+ @store = RDoc::RI::Store.new @home_ri
753
+
754
+ @cFoo = RDoc::NormalClass.new 'Foo'
755
+ @mInc = RDoc::NormalModule.new 'Inc'
756
+ @cAmbiguous = RDoc::NormalClass.new 'Ambiguous'
757
+
758
+ doc = @RM::Document.new @RM::Paragraph.new('Include thingy')
759
+
760
+ @cFooInc = RDoc::Include.new 'Inc', doc
761
+ @cFoo.add_include @cFooInc
762
+
763
+ @cFoo_Bar = RDoc::NormalClass.new 'Bar'
764
+ @cFoo_Bar.parent = @cFoo
765
+
766
+ @blah = RDoc::AnyMethod.new nil, 'blah'
767
+ @blah.call_seq = "blah(5) => 5\nblah(6) => 6\n"
768
+ @blah.block_params = "stuff"
769
+
770
+ @bother = RDoc::AnyMethod.new nil, 'bother'
771
+
772
+ @new = RDoc::AnyMethod.new nil, 'new'
773
+ @new.singleton = true
774
+
775
+ @cFoo_Bar.add_method @blah
776
+ @cFoo_Bar.add_method @bother
777
+ @cFoo_Bar.add_method @new
778
+
779
+ @attr = RDoc::Attr.new nil, 'attr', 'RW', ''
780
+
781
+ @cFoo_Bar.add_attribute @attr
782
+
783
+ @cFoo_Baz = RDoc::NormalClass.new 'Baz'
784
+ @cFoo_Baz.parent = @cFoo
785
+
786
+ @inherit = RDoc::AnyMethod.new nil, 'inherit'
787
+ @cFoo.add_method @inherit
788
+
789
+ @store.save_class @cFoo
790
+ @store.save_class @cFoo_Bar
791
+ @store.save_class @cFoo_Baz
792
+ @store.save_class @mInc
793
+ @store.save_class @cAmbiguous
794
+
795
+ @store.save_method @cFoo_Bar, @blah
796
+ @store.save_method @cFoo_Bar, @bother
797
+ @store.save_method @cFoo_Bar, @new
798
+ @store.save_method @cFoo_Bar, @attr
799
+
800
+ @store.save_method @cFoo, @inherit
801
+
802
+ @store.save_cache
803
+
804
+ @driver.stores = [@store]
805
+ end
806
+
92
807
  end
93
808
 
94
- MiniTest::Unit.autorun