3 require 'rdoc/ri/formatter'
4 require 'rdoc/ri/display'
5 require 'rdoc/ri/driver'
7 class TestRDocRIDefaultDisplay < Test::Unit::TestCase
10 @output = StringIO.new
14 @dd = RDoc::RI::DefaultDisplay.new RDoc::RI::Formatter, @width, true,
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',
30 def test_display_class_info
34 { 'name' => 'attribute', 'rw' => 'RW',
35 'comment' => [RDoc::Markup::Flow::P.new('attribute comment')] },
36 { 'name' => 'attribute_no_comment', 'rw' => 'RW',
40 { 'name' => 'class_method' },
42 'class_method_extensions' => [
43 { 'name' => 'class_method_extension' },
45 'comment' => [RDoc::Markup::Flow::P.new('SomeClass comment')],
47 { 'name' => 'CONSTANT', 'value' => '"value"',
48 'comment' => [RDoc::Markup::Flow::P.new('CONSTANT value')] },
49 { 'name' => 'CONSTANT_NOCOMMENT', 'value' => '"value"',
52 'display_name' => 'Class',
53 'full_name' => 'SomeClass',
55 'instance_methods' => [
56 { 'name' => 'instance_method' },
58 'instance_method_extensions' => [
59 { 'name' => 'instance_method_extension' },
61 'superclass_string' => 'Object',
64 @dd.display_class_info klass, ri_reader
67 ---------------------------------------------------- Class: SomeClass < Object
70 ------------------------------------------------------------------------------
88 Class method extensions:
89 ------------------------
91 class_method_extension
100 Instance method extensions:
101 ---------------------------
103 instance_method_extension
112 attribute_no_comment (RW)
115 assert_equal expected, @output.string
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
126 def test_display_flow_empty
129 assert_equal " [no description]\n", @output.string
132 def test_display_flow_nil
135 assert_equal " [no description]\n", @output.string
138 def test_display_method_info
139 @dd.display_method_info @some_method
142 -------------------------------------------------------- SomeClass#some_method
143 some_method(arg1, arg2) {|block_param| ...}
145 Extension from /nonexistent
146 ------------------------------------------------------------------------------
150 (also known as some_method_alias)
153 assert_equal expected, @output.string
156 def test_display_method_info_singleton
159 'block_params' => nil,
161 'full_name' => 'SomeClass::some_method',
162 'is_singleton' => true,
163 'name' => 'some_method',
164 'params' => '(arg1, arg2)',
165 'visibility' => 'public',
168 @dd.display_method_info method
171 ------------------------------------------------------- SomeClass::some_method
172 SomeClass::some_method(arg1, arg2)
173 ------------------------------------------------------------------------------
177 assert_equal expected, @output.string
180 def test_display_method_list
184 "block_params" => nil,
186 "full_name" => "SomeClass#some_method",
187 "is_singleton" => false,
188 "name" => "some_method",
190 "visibility" => "public",
194 "block_params" => nil,
196 "full_name" => "SomeClass#some_other_method",
197 "is_singleton" => false,
198 "name" => "some_other_method",
200 "visibility" => "public",
204 @dd.display_method_list methods
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
213 assert_equal expected, @output.string
216 def test_display_params
217 @dd.display_params @some_method
220 some_method(arg1, arg2) {|block_param| ...}
222 Extension from /nonexistent
225 assert_equal expected, @output.string
228 def test_display_params_multiple
229 @some_method['params'] = <<-EOF
231 some_method(start, length)
234 @dd.display_params @some_method
238 some_method(start, length)
240 Extension from /nonexistent
243 assert_equal expected, @output.string
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
253 SomeClass::some_method(arg1, arg2) {|block_param| ...}
255 Extension from /nonexistent
258 assert_equal expected, @output.string
261 def test_list_known_classes
262 klasses = %w[SomeClass SomeModule]
264 @dd.list_known_classes klasses
267 ---------------------------------------------------- Known classes and modules
269 SomeClass, SomeModule
272 assert_equal expected, @output.string
275 def test_list_known_classes_empty
276 @dd.list_known_classes []
281 If you've installed Ruby yourself, you need to generate documentation using:
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.
291 assert_equal expected, @output.string