Removed obsolete bin scripts.
[rbx.git] / test / rdoc / test_rdoc_ri_default_display.rb
blobd92516f3ab2f7066badff6929ef38686395f426a
1 require 'stringio'
2 require 'test/unit'
3 require 'rdoc/ri/formatter'
4 require 'rdoc/ri/display'
5 require 'rdoc/ri/driver'
7 class TestRDocRIDefaultDisplay < Test::Unit::TestCase
9   def setup
10     @output = StringIO.new
11     @width = 78
12     @indent = '  '
14     @dd = RDoc::RI::DefaultDisplay.new RDoc::RI::Formatter, @width, true,
15                                        @output
17     @some_method = {
18       'aliases' => [{'name' => 'some_method_alias'}],
19       'block_params' => 'block_param',
20       'comment' => [RDoc::Markup::Flow::P.new('some comment')],
21       'full_name' => 'SomeClass#some_method',
22       'is_singleton' => false,
23       'name' => 'some_method',
24       'params' => '(arg1, arg2) {|block_param| ...}',
25       'source_path' => '/nonexistent',
26       'visibility' => 'public',
27     }
28   end
30   def test_display_class_info
31     ri_reader = nil
32     klass = {
33       'attributes' => [
34         { 'name' => 'attribute', 'rw' => 'RW',
35           'comment' => [RDoc::Markup::Flow::P.new('attribute comment')] },
36         { 'name' => 'attribute_no_comment', 'rw' => 'RW',
37           'comment' => nil },
38       ],
39       'class_methods' => [
40         { 'name' => 'class_method' },
41       ],
42       'class_method_extensions' => [
43         { 'name' => 'class_method_extension' },
44       ],
45       'comment' => [RDoc::Markup::Flow::P.new('SomeClass comment')],
46       'constants' => [
47         { 'name' => 'CONSTANT', 'value' => '"value"',
48           'comment' => [RDoc::Markup::Flow::P.new('CONSTANT value')] },
49         { 'name' => 'CONSTANT_NOCOMMENT', 'value' => '"value"',
50           'comment' => nil },
51       ],
52       'display_name' => 'Class',
53       'full_name' => 'SomeClass',
54       'includes' => [],
55       'instance_methods' => [
56         { 'name' => 'instance_method' },
57       ],
58       'instance_method_extensions' => [
59         { 'name' => 'instance_method_extension' },
60       ],
61       'superclass_string' => 'Object',
62     }
64     @dd.display_class_info klass, ri_reader
66     expected = <<-EOF
67 ---------------------------------------------------- Class: SomeClass < Object
68      SomeClass comment
70 ------------------------------------------------------------------------------
73 Constants:
74 ----------
76      CONSTANT:
77           CONSTANT value
79      CONSTANT_NOCOMMENT
82 Class methods:
83 --------------
85      class_method
88 Class method extensions:
89 ------------------------
91      class_method_extension
94 Instance methods:
95 -----------------
97      instance_method
100 Instance method extensions:
101 ---------------------------
103      instance_method_extension
106 Attributes:
107 -----------
109      attribute (RW):
110           attribute comment
112      attribute_no_comment (RW)
113     EOF
115     assert_equal expected, @output.string
116   end
118   def test_display_flow
119     flow = [RDoc::Markup::Flow::P.new('flow')]
121     @dd.display_flow flow
123     assert_equal "     flow\n\n", @output.string
124   end
126   def test_display_flow_empty
127     @dd.display_flow []
129     assert_equal "     [no description]\n", @output.string
130   end
132   def test_display_flow_nil
133     @dd.display_flow nil
135     assert_equal "     [no description]\n", @output.string
136   end
138   def test_display_method_info
139     @dd.display_method_info @some_method
141     expected = <<-EOF
142 -------------------------------------------------------- SomeClass#some_method
143      some_method(arg1, arg2) {|block_param| ...}
145      Extension from /nonexistent
146 ------------------------------------------------------------------------------
147      some comment
150      (also known as some_method_alias)
151     EOF
153     assert_equal expected, @output.string
154   end
156   def test_display_method_info_singleton
157     method = {
158       'aliases' => [],
159       'block_params' => nil,
160       'comment' => nil,
161       'full_name' => 'SomeClass::some_method',
162       'is_singleton' => true,
163       'name' => 'some_method',
164       'params' => '(arg1, arg2)',
165       'visibility' => 'public',
166     }
168     @dd.display_method_info method
170     expected = <<-EOF
171 ------------------------------------------------------- SomeClass::some_method
172      SomeClass::some_method(arg1, arg2)
173 ------------------------------------------------------------------------------
174      [no description]
175     EOF
177     assert_equal expected, @output.string
178   end
180   def test_display_method_list
181     methods = [
182       {
183         "aliases" => [],
184         "block_params" => nil,
185         "comment" =>  nil,
186         "full_name" => "SomeClass#some_method",
187         "is_singleton" => false,
188         "name" => "some_method",
189         "params" => "()",
190         "visibility" => "public",
191       },
192       {
193         "aliases" => [],
194         "block_params" => nil,
195         "comment" => nil,
196         "full_name" => "SomeClass#some_other_method",
197         "is_singleton" => false,
198         "name" => "some_other_method",
199         "params" => "()",
200         "visibility" => "public",
201       },
202     ]
204     @dd.display_method_list methods
206     expected = <<-EOF
207      More than one method matched your request.  You can refine your search by
208      asking for information on one of:
210      SomeClass#some_method, SomeClass#some_other_method
211     EOF
213     assert_equal expected, @output.string
214   end
216   def test_display_params
217     @dd.display_params @some_method
219     expected = <<-EOF
220      some_method(arg1, arg2) {|block_param| ...}
222      Extension from /nonexistent
223     EOF
225     assert_equal expected, @output.string
226   end
228   def test_display_params_multiple
229     @some_method['params'] = <<-EOF
230 some_method(index)
231 some_method(start, length)
232     EOF
234     @dd.display_params @some_method
236     expected = <<-EOF
237      some_method(index)
238      some_method(start, length)
240      Extension from /nonexistent
241     EOF
243     assert_equal expected, @output.string
244   end
246   def test_display_params_singleton
247     @some_method['is_singleton'] = true
248     @some_method['full_name'] = 'SomeClass::some_method'
250     @dd.display_params @some_method
252     expected = <<-EOF
253      SomeClass::some_method(arg1, arg2) {|block_param| ...}
255      Extension from /nonexistent
256     EOF
258     assert_equal expected, @output.string
259   end
261   def test_list_known_classes
262     klasses = %w[SomeClass SomeModule]
264     @dd.list_known_classes klasses
266     expected = <<-EOF
267 ---------------------------------------------------- Known classes and modules
269      SomeClass, SomeModule
270     EOF
272     assert_equal expected, @output.string
273   end
275   def test_list_known_classes_empty
276     @dd.list_known_classes []
278     expected = <<-EOF
279 No ri data found
281 If you've installed Ruby yourself, you need to generate documentation using:
283   make install-doc
285 from the same place you ran `make` to build ruby.
287 If you installed Ruby from a packaging system, then you may need to
288 install an additional package, or ask the packager to enable ri generation.
289     EOF
291     assert_equal expected, @output.string
292   end