1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
|
require 'stringio'
require 'test/unit'
require 'rdoc/ri/formatter'
require 'rdoc/ri/display'
require 'rdoc/ri/driver'
class TestRDocRiDefaultDisplay < Test::Unit::TestCase
def setup
@output = StringIO.new
@width = 78
@indent = ' '
@dd = RDoc::RI::DefaultDisplay.new RDoc::RI::Formatter, @width, true,
@output
@some_method = h \
'aliases' => [{'name' => 'some_method_alias'}],
'block_params' => 'block_param',
'comment' => [RDoc::Markup::Flow::P.new('some comment')],
'full_name' => 'SomeClass#some_method',
'is_singleton' => false,
'name' => 'some_method',
'params' => '(arg1, arg2) {|block_param| ...}',
'source_path' => '/nonexistent',
'visibility' => 'public'
end
def test_display_class_info
klass = h \
'attributes' => [
{ 'name' => 'attribute', 'rw' => 'RW',
'comment' => [RDoc::Markup::Flow::P.new('attribute comment')] },
{ 'name' => 'attribute_no_comment', 'rw' => 'RW',
'comment' => nil },
],
'class_methods' => [
{ 'name' => 'class_method' },
],
'class_method_extensions' => [
{ 'name' => 'class_method_extension' },
],
'comment' => [RDoc::Markup::Flow::P.new('SomeClass comment')],
'constants' => [
{ 'name' => 'CONSTANT', 'value' => '"value1"',
'comment' => [RDoc::Markup::Flow::P.new('CONSTANT value')] },
{ 'name' => 'CONSTANT_NOCOMMENT', 'value' => '"value2"',
'comment' => nil },
],
'display_name' => 'Class',
'full_name' => 'SomeClass',
'includes' => [],
'instance_methods' => [
{ 'name' => 'instance_method' },
],
'instance_method_extensions' => [
{ 'name' => 'instance_method_extension' },
],
'superclass_string' => 'Object'
@dd.display_class_info klass
expected = <<-EOF
---------------------------------------------------- Class: SomeClass < Object
SomeClass comment
------------------------------------------------------------------------------
Constants:
----------
CONSTANT = "value1"
CONSTANT value
CONSTANT_NOCOMMENT = "value2"
Attributes:
-----------
attribute (RW):
attribute comment
attribute_no_comment (RW)
Class methods:
--------------
class_method
Class method extensions:
------------------------
class_method_extension
Instance methods:
-----------------
instance_method
Instance method extensions:
---------------------------
instance_method_extension
EOF
assert_equal expected, @output.string
end
def test_display_flow
flow = [RDoc::Markup::Flow::P.new('flow')]
@dd.display_flow flow
assert_equal " flow\n\n", @output.string
end
def test_display_flow_empty
@dd.display_flow []
assert_equal " [no description]\n", @output.string
end
def test_display_flow_nil
@dd.display_flow nil
assert_equal " [no description]\n", @output.string
end
def test_display_method_info
@dd.display_method_info @some_method
expected = <<-EOF
-------------------------------------------------------- SomeClass#some_method
some_method(arg1, arg2) {|block_param| ...}
From /nonexistent
------------------------------------------------------------------------------
some comment
(also known as some_method_alias)
EOF
assert_equal expected, @output.string
end
def test_display_method_info_singleton
method = RDoc::RI::Driver::OpenStructHash.new.update \
'aliases' => [],
'block_params' => nil,
'comment' => nil,
'full_name' => 'SomeClass::some_method',
'is_singleton' => true,
'name' => 'some_method',
'params' => '(arg1, arg2)',
'visibility' => 'public'
@dd.display_method_info method
expected = <<-EOF
------------------------------------------------------- SomeClass::some_method
SomeClass::some_method(arg1, arg2)
From
------------------------------------------------------------------------------
[no description]
EOF
assert_equal expected, @output.string
end
def test_display_method_list
methods = [
RDoc::RI::Driver::OpenStructHash.new.update(
"aliases" => [],
"block_params" => nil,
"comment" => nil,
"full_name" => "SomeClass#some_method",
"is_singleton" => false,
"name" => "some_method",
"params" => "()",
"visibility" => "public"
),
RDoc::RI::Driver::OpenStructHash.new.update(
"aliases" => [],
"block_params" => nil,
"comment" => nil,
"full_name" => "SomeClass#some_other_method",
"is_singleton" => false,
"name" => "some_other_method",
"params" => "()",
"visibility" => "public"
),
]
@dd.display_method_list methods
expected = <<-EOF
More than one method matched your request. You can refine your search by
asking for information on one of:
SomeClass#some_method []
SomeClass#some_other_method []
EOF
assert_equal expected, @output.string
end
def test_display_params
@dd.display_params @some_method
expected = <<-EOF
some_method(arg1, arg2) {|block_param| ...}
From /nonexistent
EOF
assert_equal expected, @output.string
end
def test_display_params_multiple
@some_method['params'] = <<-EOF
some_method(index)
some_method(start, length)
EOF
@dd.display_params @some_method
expected = <<-EOF
some_method(index)
some_method(start, length)
From /nonexistent
EOF
assert_equal expected, @output.string
end
def test_display_params_singleton
@some_method['is_singleton'] = true
@some_method['full_name'] = 'SomeClass::some_method'
@dd.display_params @some_method
expected = <<-EOF
SomeClass::some_method(arg1, arg2) {|block_param| ...}
From /nonexistent
EOF
assert_equal expected, @output.string
end
def test_list_known_classes
klasses = %w[SomeClass SomeModule]
@dd.list_known_classes klasses
expected = <<-EOF
---------------------------------------------------- Known classes and modules
SomeClass, SomeModule
EOF
assert_equal expected, @output.string
end
def test_list_known_classes_empty
@dd.list_known_classes []
expected = <<-EOF
No ri data found
If you've installed Ruby yourself, you need to generate documentation using:
make install-doc
from the same place you ran `make` to build ruby.
If you installed Ruby from a packaging system, then you may need to
install an additional package, or ask the packager to enable ri generation.
EOF
assert_equal expected, @output.string
end
def h(hash)
RDoc::RI::Driver::OpenStructHash.convert hash
end
end
|