Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

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