Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 677 lines (491 sloc) 19.522 kB
7757ac0 @drbrain Comments can now be merged properly based on the file they came from.…
drbrain authored
1 require 'pp'
04a96ea @drbrain Updates for 1.9
drbrain authored
2 require File.expand_path '../xref_test_case', __FILE__
390a070 @drbrain New RI generator/executable
drbrain authored
3
4 class TestRDocClassModule < XrefTestCase
5
fcf215f @drbrain Add SIGINFO support to the ri generator
drbrain authored
6 def setup
ba0a29d @drbrain Fix case 2 of #26161
drbrain authored
7 super
8
fd5a90c @drbrain RDoc::Markup::Parser::* to RDoc::Markup::*
drbrain authored
9 @RM = RDoc::Markup
fcf215f @drbrain Add SIGINFO support to the ri generator
drbrain authored
10 end
11
7757ac0 @drbrain Comments can now be merged properly based on the file they came from.…
drbrain authored
12 def mu_pp obj
13 s = ''
14 s = PP.pp obj, s
15 s.force_encoding Encoding.default_external if defined? Encoding
16 s.chomp
17 end
18
108ba0f @drbrain Add RDoc::ClassModule#add_comment which stores the comment and its lo…
drbrain authored
19 def test_add_comment
20 tl1 = RDoc::TopLevel.new 'one.rb'
21 tl2 = RDoc::TopLevel.new 'two.rb'
22 tl3 = RDoc::TopLevel.new 'three.rb'
23
24 cm = RDoc::ClassModule.new 'Klass'
25 cm.add_comment '# comment 1', tl1
26
27 assert_equal [['comment 1', tl1]], cm.comment_location
28 assert_equal 'comment 1', cm.comment
29
30 cm.add_comment '# comment 2', tl2
31
32 assert_equal [['comment 1', tl1], ['comment 2', tl2]], cm.comment_location
33 assert_equal "comment 1\n---\ncomment 2", cm.comment
34
35 cm.add_comment "# * comment 3", tl3
36
37 assert_equal [['comment 1', tl1],
38 ['comment 2', tl2],
39 ['* comment 3', tl3]], cm.comment_location
40 assert_equal "comment 1\n---\ncomment 2\n---\n* comment 3", cm.comment
41 end
42
5fb832a @drbrain Handle private_class_method and public_class_method correctly by copy…
drbrain authored
43 def test_ancestors
44 assert_equal [@parent], @child.ancestors
45 end
46
b409361 @drbrain Move where normalization of comments happens to allow merged comments to
drbrain authored
47 def test_comment_equals
48 cm = RDoc::ClassModule.new 'Klass'
49 cm.comment = '# comment 1'
50
51 assert_equal 'comment 1', cm.comment
52
53 cm.comment = '# comment 2'
54
55 assert_equal "comment 1\n---\ncomment 2", cm.comment
56
2809c74 @drbrain Put strip_stars in the right place
drbrain authored
57 cm.comment = "# * comment 3"
b409361 @drbrain Move where normalization of comments happens to allow merged comments to
drbrain authored
58
2809c74 @drbrain Put strip_stars in the right place
drbrain authored
59 assert_equal "comment 1\n---\ncomment 2\n---\n* comment 3", cm.comment
b409361 @drbrain Move where normalization of comments happens to allow merged comments to
drbrain authored
60 end
61
5fb832a @drbrain Handle private_class_method and public_class_method correctly by copy…
drbrain authored
62 def test_each_ancestor
63 ancestors = []
64
65 @child.each_ancestor do |mod|
66 ancestors << mod
67 end
68
69 assert_equal [@parent], ancestors
70 end
71
2b4b79c @drbrain Allow aliasing yourself
drbrain authored
72 # handle making a short module alias of yourself
73
74 def test_find_class_named
75 @c2.classes_hash['C2'] = @c2
76
6b9a271 @drbrain Fix warning and test
drbrain authored
77 assert_nil @c2.find_class_named('C1')
2b4b79c @drbrain Allow aliasing yourself
drbrain authored
78 end
79
e1397a7 @drbrain Add tests for marshal round-trip
drbrain authored
80 def test_marshal_dump
81 tl = RDoc::TopLevel.new 'file.rb'
3d1b629 @drbrain The ClassModule method_list now merges based on source file. Issue #21
drbrain authored
82
e1397a7 @drbrain Add tests for marshal round-trip
drbrain authored
83 ns = tl.add_module RDoc::NormalModule, 'Namespace'
3d1b629 @drbrain The ClassModule method_list now merges based on source file. Issue #21
drbrain authored
84
e1397a7 @drbrain Add tests for marshal round-trip
drbrain authored
85 cm = ns.add_class RDoc::NormalClass, 'Klass', 'Super'
a58835a @drbrain Store source file for methods and attributes. Issue #21
drbrain authored
86 cm.record_location tl
e1397a7 @drbrain Add tests for marshal round-trip
drbrain authored
87
59aee8a @drbrain Add visibility, singleton and file to attributes list in RDoc::ClassM…
drbrain authored
88 a1 = RDoc::Attr.new nil, 'a1', 'RW', ''
89 a1.record_location tl
90 a2 = RDoc::Attr.new nil, 'a2', 'RW', '', true
91 a2.record_location tl
92
93 m1 = RDoc::AnyMethod.new nil, 'm1'
3d1b629 @drbrain The ClassModule method_list now merges based on source file. Issue #21
drbrain authored
94 m1.record_location tl
8fbfa6c @drbrain The ClassModule constant list now merges based on source file. Issue…
drbrain authored
95
59aee8a @drbrain Add visibility, singleton and file to attributes list in RDoc::ClassM…
drbrain authored
96 c1 = RDoc::Constant.new 'C1', nil, ''
8fbfa6c @drbrain The ClassModule constant list now merges based on source file. Issue…
drbrain authored
97 c1.record_location tl
98
59aee8a @drbrain Add visibility, singleton and file to attributes list in RDoc::ClassM…
drbrain authored
99 i1 = RDoc::Include.new 'I1', ''
b33e086 @drbrain The ClassModule includes list now merges based on source file. Issue…
drbrain authored
100 i1.record_location tl
59aee8a @drbrain Add visibility, singleton and file to attributes list in RDoc::ClassM…
drbrain authored
101
102 cm.add_attribute a1
103 cm.add_attribute a2
104 cm.add_method m1
105 cm.add_constant c1
106 cm.add_include i1
108ba0f @drbrain Add RDoc::ClassModule#add_comment which stores the comment and its lo…
drbrain authored
107 cm.add_comment 'this is a comment', tl
e1397a7 @drbrain Add tests for marshal round-trip
drbrain authored
108
109 loaded = Marshal.load Marshal.dump cm
110
111 assert_equal cm, loaded
112
7757ac0 @drbrain Comments can now be merged properly based on the file they came from.…
drbrain authored
113 inner = RDoc::Markup::Document.new(
114 RDoc::Markup::Paragraph.new('this is a comment'))
115 inner.file = tl.absolute_name
116
117 comment = RDoc::Markup::Document.new inner
e1397a7 @drbrain Add tests for marshal round-trip
drbrain authored
118
59aee8a @drbrain Add visibility, singleton and file to attributes list in RDoc::ClassM…
drbrain authored
119 assert_equal [a2, a1], loaded.attributes.sort
e1397a7 @drbrain Add tests for marshal round-trip
drbrain authored
120 assert_equal comment, loaded.comment
59aee8a @drbrain Add visibility, singleton and file to attributes list in RDoc::ClassM…
drbrain authored
121 assert_equal [c1], loaded.constants
e1397a7 @drbrain Add tests for marshal round-trip
drbrain authored
122 assert_equal 'Namespace::Klass', loaded.full_name
59aee8a @drbrain Add visibility, singleton and file to attributes list in RDoc::ClassM…
drbrain authored
123 assert_equal [i1], loaded.includes
124 assert_equal [m1], loaded.method_list
e1397a7 @drbrain Add tests for marshal round-trip
drbrain authored
125 assert_equal 'Klass', loaded.name
126 assert_equal 'Super', loaded.superclass
59aee8a @drbrain Add visibility, singleton and file to attributes list in RDoc::ClassM…
drbrain authored
127
128 assert_equal tl, loaded.attributes.first.file
8fbfa6c @drbrain The ClassModule constant list now merges based on source file. Issue…
drbrain authored
129
130 assert_equal tl, loaded.constants.first.file
b33e086 @drbrain The ClassModule includes list now merges based on source file. Issue…
drbrain authored
131
132 assert_equal tl, loaded.includes.first.file
3d1b629 @drbrain The ClassModule method_list now merges based on source file. Issue #21
drbrain authored
133
134 assert_equal tl, loaded.method_list.first.file
e1397a7 @drbrain Add tests for marshal round-trip
drbrain authored
135 end
136
a58835a @drbrain Store source file for methods and attributes. Issue #21
drbrain authored
137 def test_marshal_load_version_0
138 tl = RDoc::TopLevel.new 'file.rb'
139 ns = tl.add_module RDoc::NormalModule, 'Namespace'
140 cm = ns.add_class RDoc::NormalClass, 'Klass', 'Super'
141
142 a = RDoc::Attr.new(nil, 'a1', 'RW', '')
143 m = RDoc::AnyMethod.new(nil, 'm1')
144 c = RDoc::Constant.new('C1', nil, '')
145 i = RDoc::Include.new('I1', '')
146
147 cm.add_attribute a
148 cm.add_method m
149 cm.add_constant c
150 cm.add_include i
108ba0f @drbrain Add RDoc::ClassModule#add_comment which stores the comment and its lo…
drbrain authored
151 cm.add_comment 'this is a comment', tl
a58835a @drbrain Store source file for methods and attributes. Issue #21
drbrain authored
152
153 loaded = Marshal.load "\x04\bU:\x16RDoc::NormalClass[\x0Ei\x00\"\nKlass" \
154 "\"\x15Namespace::KlassI\"\nSuper\x06:\x06EF" \
155 "o:\eRDoc::Markup::Document\x06:\v@parts[\x06" \
156 "o:\x1CRDoc::Markup::Paragraph\x06;\b[\x06I" \
157 "\"\x16this is a comment\x06;\x06F[\x06[\aI" \
158 "\"\aa1\x06;\x06FI\"\aRW\x06;\x06F[\x06[\aI" \
159 "\"\aC1\x06;\x06Fo;\a\x06;\b[\x00[\x06[\aI" \
160 "\"\aI1\x06;\x06Fo;\a\x06;\b[\x00[\a[\aI" \
161 "\"\nclass\x06;\x06F[\b[\a:\vpublic[\x00[\a" \
162 ":\x0Eprotected[\x00[\a:\fprivate[\x00[\aI" \
163 "\"\rinstance\x06;\x06F[\b[\a;\n[\x06I" \
164 "\"\am1\x06;\x06F[\a;\v[\x00[\a;\f[\x00"
165
166 assert_equal cm, loaded
167
168 comment = RDoc::Markup::Document.new(
169 RDoc::Markup::Paragraph.new('this is a comment'))
170
171 assert_equal [a], loaded.attributes
172 assert_equal comment, loaded.comment
173 assert_equal [c], loaded.constants
174 assert_equal 'Namespace::Klass', loaded.full_name
175 assert_equal [i], loaded.includes
176 assert_equal [m], loaded.method_list
177 assert_equal 'Klass', loaded.name
178 assert_equal 'Super', loaded.superclass
179 assert_equal nil, loaded.file
180 end
181
d3b3e18 @drbrain The ClassModule attribute list now merges based on source file. Issu…
drbrain authored
182 def test_merge_attributes
183 tl1 = RDoc::TopLevel.new 'one.rb'
184 tl2 = RDoc::TopLevel.new 'two.rb'
185
186 cm1 = RDoc::ClassModule.new 'Klass'
187
188 attr = cm1.add_attribute RDoc::Attr.new(nil, 'a1', 'RW', '')
189 attr.record_location tl1
190 attr = cm1.add_attribute RDoc::Attr.new(nil, 'a3', 'R', '')
191 attr.record_location tl1
192 attr = cm1.add_attribute RDoc::Attr.new(nil, 'a4', 'R', '')
193 attr.record_location tl1
194
195 cm2 = RDoc::ClassModule.new 'Klass'
196 # TODO allow merging when comment == ''
197 cm2.instance_variable_set :@comment, @RM::Document.new
198
199 attr = cm2.add_attribute RDoc::Attr.new(nil, 'a2', 'RW', '')
200 attr.record_location tl2
201 attr = cm2.add_attribute RDoc::Attr.new(nil, 'a3', 'W', '')
202 attr.record_location tl1
203 attr = cm2.add_attribute RDoc::Attr.new(nil, 'a4', 'W', '')
204 attr.record_location tl1
205
206 cm1.merge cm2
207
208 expected = [
209 RDoc::Attr.new(nil, 'a2', 'RW', ''),
ea29773 @drbrain Make ClassModule#merge behave like Hash#merge!. Issue #21
drbrain authored
210 RDoc::Attr.new(nil, 'a3', 'W', ''),
211 RDoc::Attr.new(nil, 'a4', 'W', ''),
d3b3e18 @drbrain The ClassModule attribute list now merges based on source file. Issu…
drbrain authored
212 ]
213
214 expected.each do |a| a.parent = cm1 end
215 assert_equal expected, cm1.attributes.sort
216 end
217
f052da8 @drbrain Add tests for merging with version 0 ClassModules. Issue #21
drbrain authored
218 def test_merge_attributes_version_0
219 tl1 = RDoc::TopLevel.new 'one.rb'
220 tl2 = RDoc::TopLevel.new 'two.rb'
221
222 cm1 = RDoc::ClassModule.new 'Klass'
223
224 attr = cm1.add_attribute RDoc::Attr.new(nil, 'a1', 'RW', '')
225 attr.record_location tl1
226 attr = cm1.add_attribute RDoc::Attr.new(nil, 'a3', 'R', '')
227 attr.record_location tl1
228 attr = cm1.add_attribute RDoc::Attr.new(nil, 'a4', 'R', '')
229 attr.record_location tl1
230
231 cm2 = RDoc::ClassModule.new 'Klass'
232 # TODO allow merging when comment == ''
233 cm2.instance_variable_set :@comment, @RM::Document.new
234
235 attr = cm2.add_attribute RDoc::Attr.new(nil, 'a2', 'RW', '')
236 attr = cm2.add_attribute RDoc::Attr.new(nil, 'a3', 'W', '')
237 attr = cm2.add_attribute RDoc::Attr.new(nil, 'a4', 'W', '')
238
239 cm1.merge cm2
240
241 expected = [
242 RDoc::Attr.new(nil, 'a1', 'RW', ''),
243 RDoc::Attr.new(nil, 'a2', 'RW', ''),
244 RDoc::Attr.new(nil, 'a3', 'RW', ''),
245 RDoc::Attr.new(nil, 'a4', 'RW', ''),
246 ]
247
248 expected.each do |a| a.parent = cm1 end
249 assert_equal expected, cm1.attributes.sort
250 end
251
3d1b629 @drbrain The ClassModule method_list now merges based on source file. Issue #21
drbrain authored
252 def test_merge_comment
253 tl1 = RDoc::TopLevel.new 'one.rb'
254 tl2 = RDoc::TopLevel.new 'two.rb'
255
256 cm1 = RDoc::ClassModule.new 'Klass'
257 cm1.add_comment 'klass 1', tl1
258
259 cm2 = RDoc::ClassModule.new 'Klass'
260 cm2.add_comment 'klass 2', tl2
ea29773 @drbrain Make ClassModule#merge behave like Hash#merge!. Issue #21
drbrain authored
261 cm2.add_comment 'klass 3', tl1
3d1b629 @drbrain The ClassModule method_list now merges based on source file. Issue #21
drbrain authored
262
263 cm2 = Marshal.load Marshal.dump cm2
264
265 cm1.merge cm2
266
ea29773 @drbrain Make ClassModule#merge behave like Hash#merge!. Issue #21
drbrain authored
267 inner1 = @RM::Document.new @RM::Paragraph.new 'klass 3'
3d1b629 @drbrain The ClassModule method_list now merges based on source file. Issue #21
drbrain authored
268 inner1.file = 'one.rb'
269 inner2 = @RM::Document.new @RM::Paragraph.new 'klass 2'
270 inner2.file = 'two.rb'
271
272 expected = @RM::Document.new inner2, inner1
273
274 assert_equal expected, cm1.comment
275 end
276
277 def test_merge_comment_version_0
278 tl = RDoc::TopLevel.new 'file.rb'
279
280 cm1 = RDoc::ClassModule.new 'Klass'
281 cm1.add_comment 'klass 1', tl
282
283 cm2 = RDoc::ClassModule.new 'Klass'
284
285 cm2.instance_variable_set(:@comment,
286 @RM::Document.new(
287 @RM::Paragraph.new('klass 2')))
ea29773 @drbrain Make ClassModule#merge behave like Hash#merge!. Issue #21
drbrain authored
288 cm2.instance_variable_set :@comment_location, @RM::Document.new(cm2.comment)
3d1b629 @drbrain The ClassModule method_list now merges based on source file. Issue #21
drbrain authored
289
290 cm1.merge cm2
291
292 inner = @RM::Document.new @RM::Paragraph.new 'klass 1'
293 inner.file = 'file.rb'
294
295 expected = @RM::Document.new \
ea29773 @drbrain Make ClassModule#merge behave like Hash#merge!. Issue #21
drbrain authored
296 inner,
297 @RM::Document.new(@RM::Paragraph.new('klass 2'))
3d1b629 @drbrain The ClassModule method_list now merges based on source file. Issue #21
drbrain authored
298
299 assert_equal expected, cm1.comment
300 end
301
8fbfa6c @drbrain The ClassModule constant list now merges based on source file. Issue…
drbrain authored
302 def test_merge_constants
303 tl1 = RDoc::TopLevel.new 'one.rb'
304 tl2 = RDoc::TopLevel.new 'two.rb'
305
306 cm1 = RDoc::ClassModule.new 'Klass'
307
308 const = cm1.add_constant RDoc::Constant.new('C1', nil, 'one')
309 const.record_location tl1
310 const = cm1.add_constant RDoc::Constant.new('C3', nil, 'one')
311 const.record_location tl1
312
313 cm2 = RDoc::ClassModule.new 'Klass'
314 cm2.instance_variable_set :@comment, @RM::Document.new
315
316 const = cm2.add_constant RDoc::Constant.new('C2', nil, 'two')
317 const.record_location tl2
ea29773 @drbrain Make ClassModule#merge behave like Hash#merge!. Issue #21
drbrain authored
318 const = cm2.add_constant RDoc::Constant.new('C3', nil, 'one')
8fbfa6c @drbrain The ClassModule constant list now merges based on source file. Issue…
drbrain authored
319 const.record_location tl1
ea29773 @drbrain Make ClassModule#merge behave like Hash#merge!. Issue #21
drbrain authored
320 const = cm2.add_constant RDoc::Constant.new('C4', nil, 'one')
8fbfa6c @drbrain The ClassModule constant list now merges based on source file. Issue…
drbrain authored
321 const.record_location tl1
322
323 cm1.merge cm2
324
325 expected = [
326 RDoc::Constant.new('C2', nil, 'two'),
327 RDoc::Constant.new('C3', nil, 'one'),
ea29773 @drbrain Make ClassModule#merge behave like Hash#merge!. Issue #21
drbrain authored
328 RDoc::Constant.new('C4', nil, 'one'),
8fbfa6c @drbrain The ClassModule constant list now merges based on source file. Issue…
drbrain authored
329 ]
330
331 expected.each do |a| a.parent = cm1 end
332
333 assert_equal expected, cm1.constants.sort
334 end
335
f052da8 @drbrain Add tests for merging with version 0 ClassModules. Issue #21
drbrain authored
336 def test_merge_constants_version_0
337 tl1 = RDoc::TopLevel.new 'one.rb'
338 tl2 = RDoc::TopLevel.new 'two.rb'
339
340 cm1 = RDoc::ClassModule.new 'Klass'
341
342 const = cm1.add_constant RDoc::Constant.new('C1', nil, 'one')
343 const.record_location tl1
344 const = cm1.add_constant RDoc::Constant.new('C3', nil, 'one')
345 const.record_location tl1
346
347 cm2 = RDoc::ClassModule.new 'Klass'
348 cm2.instance_variable_set :@comment, @RM::Document.new
349
350 const = cm2.add_constant RDoc::Constant.new('C2', nil, 'two')
351 const = cm2.add_constant RDoc::Constant.new('C3', nil, 'two')
352 const = cm2.add_constant RDoc::Constant.new('C4', nil, 'two')
353
354 cm1.merge cm2
355
356 expected = [
357 RDoc::Constant.new('C1', nil, 'one'),
358 RDoc::Constant.new('C2', nil, 'two'),
359 RDoc::Constant.new('C3', nil, 'one'),
360 RDoc::Constant.new('C4', nil, 'two'),
361 ]
362
363 expected.each do |a| a.parent = cm1 end
364
365 assert_equal expected, cm1.constants.sort
366 end
367
b33e086 @drbrain The ClassModule includes list now merges based on source file. Issue…
drbrain authored
368 def test_merge_includes
369 tl1 = RDoc::TopLevel.new 'one.rb'
370 tl2 = RDoc::TopLevel.new 'two.rb'
371
372 cm1 = RDoc::ClassModule.new 'Klass'
373
374 incl = cm1.add_include RDoc::Include.new('I1', 'one')
375 incl.record_location tl1
376 incl = cm1.add_include RDoc::Include.new('I3', 'one')
377 incl.record_location tl1
378
379 cm2 = RDoc::ClassModule.new 'Klass'
380 cm2.instance_variable_set :@comment, @RM::Document.new
381
382 incl = cm2.add_include RDoc::Include.new('I2', 'two')
383 incl.record_location tl2
ea29773 @drbrain Make ClassModule#merge behave like Hash#merge!. Issue #21
drbrain authored
384 incl = cm2.add_include RDoc::Include.new('I3', 'one')
b33e086 @drbrain The ClassModule includes list now merges based on source file. Issue…
drbrain authored
385 incl.record_location tl1
ea29773 @drbrain Make ClassModule#merge behave like Hash#merge!. Issue #21
drbrain authored
386 incl = cm2.add_include RDoc::Include.new('I4', 'one')
b33e086 @drbrain The ClassModule includes list now merges based on source file. Issue…
drbrain authored
387 incl.record_location tl1
388
389 cm1.merge cm2
390
391 expected = [
392 RDoc::Include.new('I2', 'two'),
393 RDoc::Include.new('I3', 'one'),
ea29773 @drbrain Make ClassModule#merge behave like Hash#merge!. Issue #21
drbrain authored
394 RDoc::Include.new('I4', 'one'),
b33e086 @drbrain The ClassModule includes list now merges based on source file. Issue…
drbrain authored
395 ]
396
397 expected.each do |a| a.parent = cm1 end
398
399 assert_equal expected, cm1.includes.sort
400 end
401
f052da8 @drbrain Add tests for merging with version 0 ClassModules. Issue #21
drbrain authored
402 def test_merge_includes_version_0
403 tl1 = RDoc::TopLevel.new 'one.rb'
404 tl2 = RDoc::TopLevel.new 'two.rb'
405
406 cm1 = RDoc::ClassModule.new 'Klass'
407
408 incl = cm1.add_include RDoc::Include.new('I1', 'one')
409 incl.record_location tl1
410 incl = cm1.add_include RDoc::Include.new('I3', 'one')
411 incl.record_location tl1
412
413 cm2 = RDoc::ClassModule.new 'Klass'
414 cm2.instance_variable_set :@comment, @RM::Document.new
415
416 incl = cm2.add_include RDoc::Include.new('I2', 'two')
417 incl = cm2.add_include RDoc::Include.new('I3', 'two')
418 incl = cm2.add_include RDoc::Include.new('I4', 'two')
419
420 cm1.merge cm2
421
422 expected = [
423 RDoc::Include.new('I1', 'one'),
424 RDoc::Include.new('I2', 'two'),
425 RDoc::Include.new('I3', 'one'),
426 RDoc::Include.new('I4', 'two'),
427 ]
428
429 expected.each do |a| a.parent = cm1 end
430
431 assert_equal expected, cm1.includes.sort
432 end
433
3d1b629 @drbrain The ClassModule method_list now merges based on source file. Issue #21
drbrain authored
434 def test_merge_methods
435 tl1 = RDoc::TopLevel.new 'one.rb'
436 tl2 = RDoc::TopLevel.new 'two.rb'
437
438 cm1 = RDoc::ClassModule.new 'Klass'
439
440 meth = cm1.add_method RDoc::AnyMethod.new(nil, 'm1')
441 meth.record_location tl1
442 meth = cm1.add_method RDoc::AnyMethod.new(nil, 'm3')
443 meth.record_location tl1
444
445 cm2 = RDoc::ClassModule.new 'Klass'
446 cm2.instance_variable_set :@comment, @RM::Document.new
447
448 meth = cm2.add_method RDoc::AnyMethod.new(nil, 'm2')
449 meth.record_location tl2
450 meth = cm2.add_method RDoc::AnyMethod.new(nil, 'm3')
451 meth.record_location tl1
452 meth = cm2.add_method RDoc::AnyMethod.new(nil, 'm4')
453 meth.record_location tl1
454
455 cm1.merge cm2
456
457 expected = [
458 RDoc::AnyMethod.new(nil, 'm2'),
459 RDoc::AnyMethod.new(nil, 'm3'),
ea29773 @drbrain Make ClassModule#merge behave like Hash#merge!. Issue #21
drbrain authored
460 RDoc::AnyMethod.new(nil, 'm4'),
3d1b629 @drbrain The ClassModule method_list now merges based on source file. Issue #21
drbrain authored
461 ]
462
463 expected.each do |a| a.parent = cm1 end
464
465 assert_equal expected, cm1.method_list.sort
466 end
467
f052da8 @drbrain Add tests for merging with version 0 ClassModules. Issue #21
drbrain authored
468 def test_merge_methods_version_0
469 tl1 = RDoc::TopLevel.new 'one.rb'
470 tl2 = RDoc::TopLevel.new 'two.rb'
471
472 cm1 = RDoc::ClassModule.new 'Klass'
473
474 meth = cm1.add_method RDoc::AnyMethod.new(nil, 'm1')
475 meth.record_location tl1
476 meth = cm1.add_method RDoc::AnyMethod.new(nil, 'm3')
477 meth.record_location tl1
478
479 cm2 = RDoc::ClassModule.new 'Klass'
480 cm2.instance_variable_set :@comment, @RM::Document.new
481
482 meth = cm2.add_method RDoc::AnyMethod.new(nil, 'm2')
483 meth = cm2.add_method RDoc::AnyMethod.new(nil, 'm3')
484 meth = cm2.add_method RDoc::AnyMethod.new(nil, 'm4')
485
486 cm1.merge cm2
487
488 expected = [
489 RDoc::AnyMethod.new(nil, 'm1'),
490 RDoc::AnyMethod.new(nil, 'm2'),
491 RDoc::AnyMethod.new(nil, 'm3'),
492 RDoc::AnyMethod.new(nil, 'm4'),
493 ]
494
495 expected.each do |a| a.parent = cm1 end
496
497 assert_equal expected, cm1.method_list.sort
498 end
499
7757ac0 @drbrain Comments can now be merged properly based on the file they came from.…
drbrain authored
500 def test_parse
501 tl1 = RDoc::TopLevel.new 'one.rb'
502 tl2 = RDoc::TopLevel.new 'two.rb'
503
504 cm = RDoc::ClassModule.new 'Klass'
505 cm.add_comment 'comment 1', tl1
506 cm.add_comment 'comment 2', tl2
507
508 doc1 = @RM::Document.new @RM::Paragraph.new 'comment 1'
509 doc1.file = tl1.absolute_name
510 doc2 = @RM::Document.new @RM::Paragraph.new 'comment 2'
511 doc2.file = tl2.absolute_name
512
513 expected = @RM::Document.new doc1, doc2
514
515 assert_equal expected, cm.parse(cm.comment_location)
516 end
517
ea29773 @drbrain Make ClassModule#merge behave like Hash#merge!. Issue #21
drbrain authored
518 def test_parse_comment_location
519 tl1 = RDoc::TopLevel.new 'one.rb'
520 tl2 = RDoc::TopLevel.new 'two.rb'
521
522 cm = RDoc::ClassModule.new 'Klass'
523 cm.add_comment 'comment 1', tl1
524 cm.add_comment 'comment 2', tl2
525
526 cm = Marshal.load Marshal.dump cm
527
528 doc1 = @RM::Document.new @RM::Paragraph.new 'comment 1'
529 doc1.file = tl1.absolute_name
530 doc2 = @RM::Document.new @RM::Paragraph.new 'comment 2'
531 doc2.file = tl2.absolute_name
532
533 expected = @RM::Document.new doc1, doc2
534
535 assert_same cm.comment_location, cm.parse(cm.comment_location)
536 end
537
ddc8fb6 @drbrain Move remove_nodoc_children to RDoc::ClassModules
drbrain authored
538 def test_remove_nodoc_children
539 parent = RDoc::ClassModule.new 'A'
540 parent.modules_hash.replace 'B' => true, 'C' => true
541 RDoc::TopLevel.all_modules_hash.replace 'A::B' => true
542
543 parent.classes_hash.replace 'D' => true, 'E' => true
544 RDoc::TopLevel.all_classes_hash.replace 'A::D' => true
545
546 parent.remove_nodoc_children
547
548 assert_equal %w[B], parent.modules_hash.keys
549 assert_equal %w[D], parent.classes_hash.keys
550 end
551
ba0a29d @drbrain Fix case 2 of #26161
drbrain authored
552 def test_superclass
553 assert_equal @c3_h1, @c3_h2.superclass
554 end
555
3a065ea @drbrain Order tests
drbrain authored
556 def test_update_aliases_class
557 n1 = @xref_data.add_module RDoc::NormalClass, 'N1'
558 n1_k2 = n1.add_module RDoc::NormalClass, 'N2'
2a80513 @drbrain Fix full_name for aliased modules. Patch by Thierry Lambert.
drbrain authored
559
2b73a5a @drbrain Fix warnings
drbrain authored
560 n1.add_module_alias n1_k2, 'A1', @xref_data
3a065ea @drbrain Order tests
drbrain authored
561
562 n1_a1_c = n1.constants.find { |c| c.name == 'A1' }
563 refute_nil n1_a1_c
564 assert_equal n1_k2, n1_a1_c.is_alias_for, 'sanity check'
565
566 n1.update_aliases
567
568 n1_a1_k = @xref_data.find_class_or_module 'N1::A1'
569 refute_nil n1_a1_k
570 assert_equal n1_k2, n1_a1_k.is_alias_for
571 refute_equal n1_k2, n1_a1_k
572
573 assert_equal 1, n1_k2.aliases.length
574 assert_equal n1_a1_k, n1_k2.aliases.first
575
576 assert_equal 'N1::N2', n1_k2.full_name
577 assert_equal 'N1::A1', n1_a1_k.full_name
578 end
579
580 def test_update_aliases_module
2a80513 @drbrain Fix full_name for aliased modules. Patch by Thierry Lambert.
drbrain authored
581 n1 = @xref_data.add_module RDoc::NormalModule, 'N1'
582 n1_n2 = n1.add_module RDoc::NormalModule, 'N2'
583
2b73a5a @drbrain Fix warnings
drbrain authored
584 n1.add_module_alias n1_n2, 'A1', @xref_data
9dd5c10 @drbrain Move RDoc::TopLevel::update_aliases to RDoc::ClassMethods#update_aliases
drbrain authored
585
2a80513 @drbrain Fix full_name for aliased modules. Patch by Thierry Lambert.
drbrain authored
586 n1_a1_c = n1.constants.find { |c| c.name == 'A1' }
587 refute_nil n1_a1_c
3a065ea @drbrain Order tests
drbrain authored
588 assert_equal n1_n2, n1_a1_c.is_alias_for, 'sanity check'
9dd5c10 @drbrain Move RDoc::TopLevel::update_aliases to RDoc::ClassMethods#update_aliases
drbrain authored
589
2a80513 @drbrain Fix full_name for aliased modules. Patch by Thierry Lambert.
drbrain authored
590 n1.update_aliases
9dd5c10 @drbrain Move RDoc::TopLevel::update_aliases to RDoc::ClassMethods#update_aliases
drbrain authored
591
2a80513 @drbrain Fix full_name for aliased modules. Patch by Thierry Lambert.
drbrain authored
592 n1_a1_m = @xref_data.find_class_or_module 'N1::A1'
593 refute_nil n1_a1_m
594 assert_equal n1_n2, n1_a1_m.is_alias_for
595 refute_equal n1_n2, n1_a1_m
596
597 assert_equal 1, n1_n2.aliases.length
3a065ea @drbrain Order tests
drbrain authored
598 assert_equal n1_a1_m, n1_n2.aliases.first
2a80513 @drbrain Fix full_name for aliased modules. Patch by Thierry Lambert.
drbrain authored
599
600 assert_equal 'N1::N2', n1_n2.full_name
601 assert_equal 'N1::A1', n1_a1_m.full_name
9dd5c10 @drbrain Move RDoc::TopLevel::update_aliases to RDoc::ClassMethods#update_aliases
drbrain authored
602 end
603
4f0dcfe @drbrain Add test for reparenting an alias
drbrain authored
604 def test_update_aliases_reparent
2a80513 @drbrain Fix full_name for aliased modules. Patch by Thierry Lambert.
drbrain authored
605 l1 = @xref_data.add_module RDoc::NormalModule, 'L1'
606 l1_l2 = l1.add_module RDoc::NormalModule, 'L2'
607 o1 = @xref_data.add_module RDoc::NormalModule, 'O1'
608
2b73a5a @drbrain Fix warnings
drbrain authored
609 o1.add_module_alias l1_l2, 'A1', @xref_data
2a80513 @drbrain Fix full_name for aliased modules. Patch by Thierry Lambert.
drbrain authored
610
611 o1_a1_c = o1.constants.find { |c| c.name == 'A1' }
612 refute_nil o1_a1_c
613 assert_equal l1_l2, o1_a1_c.is_alias_for
614 refute_equal l1_l2, o1_a1_c
615
616 o1.update_aliases
617
618 o1_a1_m = @xref_data.find_class_or_module 'O1::A1'
619 refute_nil o1_a1_m
620 assert_equal l1_l2, o1_a1_m.is_alias_for
4f0dcfe @drbrain Add test for reparenting an alias
drbrain authored
621
2a80513 @drbrain Fix full_name for aliased modules. Patch by Thierry Lambert.
drbrain authored
622 assert_equal 1, l1_l2.aliases.length
623 assert_equal o1_a1_m, l1_l2.aliases[0]
4f0dcfe @drbrain Add test for reparenting an alias
drbrain authored
624
2a80513 @drbrain Fix full_name for aliased modules. Patch by Thierry Lambert.
drbrain authored
625 assert_equal 'L1::L2', l1_l2.full_name
626 assert_equal 'O1::A1', o1_a1_m.full_name
4f0dcfe @drbrain Add test for reparenting an alias
drbrain authored
627 end
628
d6e293b @drbrain Move RDoc::TopLevel::update_includes to RDoc::ClassModule#update_incl…
drbrain authored
629 def test_update_includes
630 a = RDoc::Include.new 'M1', nil
631 b = RDoc::Include.new 'M2', nil
632 c = RDoc::Include.new 'C', nil
633
26da62d @drbrain Fix bug with namespace resolution for includes. Patch by Thierry Lam…
drbrain authored
634 @c1.add_include a
635 @c1.add_include b
636 @c1.add_include c
637 @c1.ancestors # cache included modules
d6e293b @drbrain Move RDoc::TopLevel::update_includes to RDoc::ClassModule#update_incl…
drbrain authored
638
639 @m1_m2.document_self = nil
26da62d @drbrain Fix bug with namespace resolution for includes. Patch by Thierry Lam…
drbrain authored
640 assert @m1_m2.remove_from_documentation?
d6e293b @drbrain Move RDoc::TopLevel::update_includes to RDoc::ClassModule#update_incl…
drbrain authored
641
26da62d @drbrain Fix bug with namespace resolution for includes. Patch by Thierry Lam…
drbrain authored
642 assert RDoc::TopLevel.all_modules_hash.key? @m1_m2.full_name
643 refute RDoc::TopLevel.all_modules_hash[@m1_m2.full_name].nil?
d6e293b @drbrain Move RDoc::TopLevel::update_includes to RDoc::ClassModule#update_incl…
drbrain authored
644 RDoc::TopLevel.remove_nodoc RDoc::TopLevel.all_modules_hash
26da62d @drbrain Fix bug with namespace resolution for includes. Patch by Thierry Lam…
drbrain authored
645 refute RDoc::TopLevel.all_modules_hash.key? @m1_m2.full_name
d6e293b @drbrain Move RDoc::TopLevel::update_includes to RDoc::ClassModule#update_incl…
drbrain authored
646
26da62d @drbrain Fix bug with namespace resolution for includes. Patch by Thierry Lam…
drbrain authored
647 @c1.update_includes
d6e293b @drbrain Move RDoc::TopLevel::update_includes to RDoc::ClassModule#update_incl…
drbrain authored
648
26da62d @drbrain Fix bug with namespace resolution for includes. Patch by Thierry Lam…
drbrain authored
649 assert_equal [a, c], @c1.includes
d6e293b @drbrain Move RDoc::TopLevel::update_includes to RDoc::ClassModule#update_incl…
drbrain authored
650 end
651
26da62d @drbrain Fix bug with namespace resolution for includes. Patch by Thierry Lam…
drbrain authored
652 def test_update_includes_with_colons
d6e293b @drbrain Move RDoc::TopLevel::update_includes to RDoc::ClassModule#update_incl…
drbrain authored
653 a = RDoc::Include.new 'M1', nil
654 b = RDoc::Include.new 'M1::M2', nil
655 c = RDoc::Include.new 'C', nil
656
26da62d @drbrain Fix bug with namespace resolution for includes. Patch by Thierry Lam…
drbrain authored
657 @c1.add_include a
658 @c1.add_include b
659 @c1.add_include c
660 @c1.ancestors # cache included modules
d6e293b @drbrain Move RDoc::TopLevel::update_includes to RDoc::ClassModule#update_incl…
drbrain authored
661
662 @m1_m2.document_self = nil
26da62d @drbrain Fix bug with namespace resolution for includes. Patch by Thierry Lam…
drbrain authored
663 assert @m1_m2.remove_from_documentation?
d6e293b @drbrain Move RDoc::TopLevel::update_includes to RDoc::ClassModule#update_incl…
drbrain authored
664
26da62d @drbrain Fix bug with namespace resolution for includes. Patch by Thierry Lam…
drbrain authored
665 assert RDoc::TopLevel.all_modules_hash.key? @m1_m2.full_name
666 refute RDoc::TopLevel.all_modules_hash[@m1_m2.full_name].nil?
d6e293b @drbrain Move RDoc::TopLevel::update_includes to RDoc::ClassModule#update_incl…
drbrain authored
667 RDoc::TopLevel.remove_nodoc RDoc::TopLevel.all_modules_hash
26da62d @drbrain Fix bug with namespace resolution for includes. Patch by Thierry Lam…
drbrain authored
668 refute RDoc::TopLevel.all_modules_hash.key? @m1_m2.full_name
d6e293b @drbrain Move RDoc::TopLevel::update_includes to RDoc::ClassModule#update_incl…
drbrain authored
669
26da62d @drbrain Fix bug with namespace resolution for includes. Patch by Thierry Lam…
drbrain authored
670 @c1.update_includes
d6e293b @drbrain Move RDoc::TopLevel::update_includes to RDoc::ClassModule#update_incl…
drbrain authored
671
26da62d @drbrain Fix bug with namespace resolution for includes. Patch by Thierry Lam…
drbrain authored
672 assert_equal [a, c], @c1.includes
d6e293b @drbrain Move RDoc::TopLevel::update_includes to RDoc::ClassModule#update_incl…
drbrain authored
673 end
674
390a070 @drbrain New RI generator/executable
drbrain authored
675 end
676
Something went wrong with that request. Please try again.