1require File.expand_path '../xref_test_case', __FILE__ 2 3class TestRDocClassModule < XrefTestCase 4 5 def mu_pp obj 6 s = '' 7 s = PP.pp obj, s 8 s.force_encoding Encoding.default_external if defined? Encoding 9 s.chomp 10 end 11 12 def test_add_comment 13 tl1 = @store.add_file 'one.rb' 14 tl2 = @store.add_file 'two.rb' 15 tl3 = @store.add_file 'three.rb' 16 17 cm = RDoc::ClassModule.new 'Klass' 18 cm.add_comment '# comment 1', tl1 19 20 assert_equal [['comment 1', tl1]], cm.comment_location 21 assert_equal 'comment 1', cm.comment 22 23 cm.add_comment '# comment 2', tl2 24 25 assert_equal [['comment 1', tl1], ['comment 2', tl2]], cm.comment_location 26 assert_equal "comment 1\n---\ncomment 2", cm.comment 27 28 cm.add_comment "# * comment 3", tl3 29 30 assert_equal [['comment 1', tl1], 31 ['comment 2', tl2], 32 ['* comment 3', tl3]], cm.comment_location 33 assert_equal "comment 1\n---\ncomment 2\n---\n* comment 3", cm.comment 34 end 35 36 def test_add_comment_comment 37 cm = RDoc::ClassModule.new 'Klass' 38 39 cm.add_comment comment('comment'), @top_level 40 41 assert_equal 'comment', cm.comment.text 42 end 43 44 def test_add_comment_duplicate 45 tl1 = @store.add_file 'one.rb' 46 47 cm = RDoc::ClassModule.new 'Klass' 48 cm.add_comment '# comment 1', tl1 49 cm.add_comment '# comment 2', tl1 50 51 assert_equal [['comment 2', tl1]], cm.comment_location 52 end 53 54 def test_add_comment_stopdoc 55 tl = @store.add_file 'file.rb' 56 57 cm = RDoc::ClassModule.new 'Klass' 58 cm.stop_doc 59 60 cm.add_comment '# comment 1', tl 61 62 assert_empty cm.comment 63 end 64 65 def test_ancestors 66 assert_equal [@parent, "Object"], @child.ancestors 67 end 68 69 def test_comment_equals 70 cm = RDoc::ClassModule.new 'Klass' 71 cm.comment = '# comment 1' 72 73 assert_equal 'comment 1', cm.comment 74 75 cm.comment = '# comment 2' 76 77 assert_equal "comment 1\n---\ncomment 2", cm.comment 78 79 cm.comment = "# * comment 3" 80 81 assert_equal "comment 1\n---\ncomment 2\n---\n* comment 3", cm.comment 82 end 83 84 def test_comment_equals_comment 85 cm = RDoc::ClassModule.new 'Klass' 86 87 cm.comment = comment 'comment' 88 89 assert_equal 'comment', cm.comment.text 90 end 91 92 def test_docuent_self_or_methods 93 assert @c1.document_self_or_methods 94 95 @c1.document_self = false 96 97 assert @c1.document_self_or_methods 98 99 @c1_m.document_self = false 100 101 assert @c1.document_self_or_methods 102 103 @c1__m.document_self = false 104 105 refute @c1.document_self_or_methods 106 end 107 108 def test_documented_eh 109 cm = RDoc::ClassModule.new 'C' 110 111 refute cm.documented? 112 113 cm.add_comment 'hi', @top_level 114 115 assert cm.documented? 116 117 cm.comment.replace '' 118 119 assert cm.documented? 120 121 cm.comment_location.clear 122 123 refute cm.documented? 124 125 cm.document_self = nil # notify :nodoc: 126 127 assert cm.documented? 128 end 129 130 def test_each_ancestor 131 assert_equal [@parent], @child.each_ancestor.to_a 132 end 133 134 def test_each_ancestor_cycle 135 m_incl = RDoc::Include.new 'M', nil 136 137 m = @top_level.add_module RDoc::NormalModule, 'M' 138 m.add_include m_incl 139 140 assert_empty m.each_ancestor.to_a 141 end 142 143 # handle making a short module alias of yourself 144 145 def test_find_class_named 146 @c2.classes_hash['C2'] = @c2 147 148 assert_nil @c2.find_class_named('C1') 149 end 150 151 def test_from_module_comment 152 tl = @store.add_file 'file.rb' 153 klass = tl.add_class RDoc::NormalModule, 'Klass' 154 klass.add_comment 'really a class', tl 155 156 klass = RDoc::ClassModule.from_module RDoc::NormalClass, klass 157 158 assert_equal [['really a class', tl]], klass.comment_location 159 end 160 161 def test_marshal_dump 162 @store.path = Dir.tmpdir 163 tl = @store.add_file 'file.rb' 164 165 ns = tl.add_module RDoc::NormalModule, 'Namespace' 166 167 cm = ns.add_class RDoc::NormalClass, 'Klass', 'Super' 168 cm.record_location tl 169 170 a1 = RDoc::Attr.new nil, 'a1', 'RW', '' 171 a1.record_location tl 172 a2 = RDoc::Attr.new nil, 'a2', 'RW', '', true 173 a2.record_location tl 174 175 m1 = RDoc::AnyMethod.new nil, 'm1' 176 m1.record_location tl 177 178 c1 = RDoc::Constant.new 'C1', nil, '' 179 c1.record_location tl 180 181 i1 = RDoc::Include.new 'I1', '' 182 i1.record_location tl 183 184 e1 = RDoc::Extend.new 'E1', '' 185 e1.record_location tl 186 187 section_comment = RDoc::Comment.new('section comment') 188 section_comment.location = tl 189 190 assert_equal 1, cm.sections.length, 'sanity, default section only' 191 s0 = cm.sections.first 192 s1 = cm.add_section 'section', section_comment 193 194 cm.add_attribute a1 195 cm.add_attribute a2 196 cm.add_method m1 197 cm.add_constant c1 198 cm.add_include i1 199 cm.add_extend e1 200 cm.add_comment 'this is a comment', tl 201 202 loaded = Marshal.load Marshal.dump cm 203 loaded.store = @store 204 205 assert_equal cm, loaded 206 207 inner = RDoc::Markup::Document.new( 208 RDoc::Markup::Paragraph.new('this is a comment')) 209 inner.file = tl 210 211 comment = RDoc::Markup::Document.new inner 212 213 assert_equal [a2, a1], loaded.attributes.sort 214 assert_equal comment, loaded.comment 215 assert_equal [c1], loaded.constants 216 assert_equal 'Namespace::Klass', loaded.full_name 217 assert_equal [i1], loaded.includes 218 assert_equal [e1], loaded.extends 219 assert_equal [m1], loaded.method_list 220 assert_equal 'Klass', loaded.name 221 assert_equal 'Super', loaded.superclass 222 assert_equal [tl], loaded.in_files 223 assert_equal 'Namespace', loaded.parent.name 224 225 expected = { nil => s0, 'section' => s1 } 226 assert_equal expected, loaded.sections_hash 227 228 assert_equal tl, loaded.attributes.first.file 229 230 assert_equal tl, loaded.constants.first.file 231 232 assert_equal tl, loaded.includes.first.file 233 234 assert_equal tl, loaded.extends.first.file 235 236 assert_equal tl, loaded.method_list.first.file 237 end 238 239 def test_marshal_load_version_0 240 tl = @store.add_file 'file.rb' 241 ns = tl.add_module RDoc::NormalModule, 'Namespace' 242 cm = ns.add_class RDoc::NormalClass, 'Klass', 'Super' 243 244 a = RDoc::Attr.new(nil, 'a1', 'RW', '') 245 m = RDoc::AnyMethod.new(nil, 'm1') 246 c = RDoc::Constant.new('C1', nil, '') 247 i = RDoc::Include.new('I1', '') 248 249 s0 = cm.sections.first 250 251 cm.add_attribute a 252 cm.add_method m 253 cm.add_constant c 254 cm.add_include i 255 cm.add_comment 'this is a comment', tl 256 257 loaded = Marshal.load "\x04\bU:\x16RDoc::NormalClass[\x0Ei\x00\"\nKlass" + 258 "\"\x15Namespace::KlassI\"\nSuper\x06:\x06EF" + 259 "o:\eRDoc::Markup::Document\x06:\v@parts[\x06" + 260 "o:\x1CRDoc::Markup::Paragraph\x06;\b[\x06I" + 261 "\"\x16this is a comment\x06;\x06F[\x06[\aI" + 262 "\"\aa1\x06;\x06FI\"\aRW\x06;\x06F[\x06[\aI" + 263 "\"\aC1\x06;\x06Fo;\a\x06;\b[\x00[\x06[\aI" + 264 "\"\aI1\x06;\x06Fo;\a\x06;\b[\x00[\a[\aI" + 265 "\"\nclass\x06;\x06F[\b[\a:\vpublic[\x00[\a" + 266 ":\x0Eprotected[\x00[\a:\fprivate[\x00[\aI" + 267 "\"\rinstance\x06;\x06F[\b[\a;\n[\x06I" + 268 "\"\am1\x06;\x06F[\a;\v[\x00[\a;\f[\x00" 269 270 loaded.store = @store 271 272 assert_equal cm, loaded 273 274 comment = RDoc::Markup::Document.new( 275 RDoc::Markup::Paragraph.new('this is a comment')) 276 277 assert_equal [a], loaded.attributes 278 assert_equal comment, loaded.comment 279 assert_equal [c], loaded.constants 280 assert_equal 'Namespace::Klass', loaded.full_name 281 assert_equal [i], loaded.includes 282 assert_equal [m], loaded.method_list 283 assert_equal 'Klass', loaded.name 284 assert_equal 'Super', loaded.superclass 285 assert_nil loaded.file 286 assert_empty loaded.in_files 287 assert_nil loaded.parent 288 assert loaded.current_section 289 290 expected = { nil => s0 } 291 assert_equal expected, loaded.sections_hash 292 293 assert loaded.display? 294 end 295 296 def test_marshal_load_version_1 297 tl = @store.add_file 'file.rb' 298 299 ns = tl.add_module RDoc::NormalModule, 'Namespace' 300 301 cm = ns.add_class RDoc::NormalClass, 'Klass', 'Super' 302 cm.record_location tl 303 304 a1 = RDoc::Attr.new nil, 'a1', 'RW', '' 305 a1.record_location tl 306 a2 = RDoc::Attr.new nil, 'a2', 'RW', '', true 307 a2.record_location tl 308 309 m1 = RDoc::AnyMethod.new nil, 'm1' 310 m1.record_location tl 311 312 c1 = RDoc::Constant.new 'C1', nil, '' 313 c1.record_location tl 314 315 i1 = RDoc::Include.new 'I1', '' 316 i1.record_location tl 317 318 s0 = cm.sections.first 319 320 cm.add_attribute a1 321 cm.add_attribute a2 322 cm.add_method m1 323 cm.add_constant c1 324 cm.add_include i1 325 cm.add_comment 'this is a comment', tl 326 327 loaded = Marshal.load "\x04\bU:\x16RDoc::NormalClass[\x0Ei\x06I\"\nKlass" + 328 "\x06:\x06EFI\"\x15Namespace::Klass\x06;\x06FI" + 329 "\"\nSuper\x06;\x06Fo:\eRDoc::Markup::Document\a" + 330 ":\v@parts[\x06o;\a\a;\b[\x06o" + 331 ":\x1CRDoc::Markup::Paragraph\x06;\b" + 332 "[\x06I\"\x16this is a comment\x06;\x06F" + 333 ":\n@fileI\"\ffile.rb\x06;\x06F;\n0[\a[\nI" + 334 "\"\aa2\x06;\x06FI\"\aRW\x06;\x06F:\vpublicT@\x11" + 335 "[\nI\"\aa1\x06;\x06FI\"\aRW\x06;\x06F;\vF@\x11" + 336 "[\x06[\bI\"\aC1\x06;\x06Fo;\a\a;\b[\x00;\n0@\x11" + 337 "[\x06[\bI\"\aI1\x06;\x06Fo;\a\a;\b[\x00;\n0@\x11" + 338 "[\a[\aI\"\nclass\x06;\x06F[\b[\a;\v[\x00" + 339 "[\a:\x0Eprotected[\x00[\a:\fprivate[\x00[\aI" + 340 "\"\rinstance\x06;\x06F[\b[\a;\v[\x06[\aI" + 341 "\"\am1\x06;\x06F@\x11[\a;\f[\x00[\a;\r[\x00" 342 343 loaded.store = @store 344 345 assert_equal cm, loaded 346 347 inner = RDoc::Markup::Document.new( 348 RDoc::Markup::Paragraph.new('this is a comment')) 349 inner.file = tl 350 351 comment = RDoc::Markup::Document.new inner 352 353 assert_equal [a2, a1], loaded.attributes.sort 354 assert_equal comment, loaded.comment 355 assert_equal [c1], loaded.constants 356 assert_equal 'Namespace::Klass', loaded.full_name 357 assert_equal [i1], loaded.includes 358 assert_empty loaded.extends 359 assert_equal [m1], loaded.method_list 360 assert_equal 'Klass', loaded.name 361 assert_equal 'Super', loaded.superclass 362 assert_empty loaded.in_files 363 assert_nil loaded.parent 364 assert loaded.current_section 365 366 assert_equal tl, loaded.attributes.first.file 367 assert_equal tl, loaded.constants.first.file 368 assert_equal tl, loaded.includes.first.file 369 assert_equal tl, loaded.method_list.first.file 370 371 expected = { nil => s0 } 372 assert_equal expected, loaded.sections_hash 373 end 374 375 def test_marshal_load_version_2 376 tl = @store.add_file 'file.rb' 377 378 ns = tl.add_module RDoc::NormalModule, 'Namespace' 379 380 cm = ns.add_class RDoc::NormalClass, 'Klass', 'Super' 381 cm.record_location tl 382 383 a1 = RDoc::Attr.new nil, 'a1', 'RW', '' 384 a1.record_location tl 385 a2 = RDoc::Attr.new nil, 'a2', 'RW', '', true 386 a2.record_location tl 387 388 m1 = RDoc::AnyMethod.new nil, 'm1' 389 m1.record_location tl 390 391 c1 = RDoc::Constant.new 'C1', nil, '' 392 c1.record_location tl 393 394 i1 = RDoc::Include.new 'I1', '' 395 i1.record_location tl 396 397 e1 = RDoc::Extend.new 'E1', '' 398 e1.record_location tl 399 400 s0 = cm.sections.first 401 402 cm.add_attribute a1 403 cm.add_attribute a2 404 cm.add_method m1 405 cm.add_constant c1 406 cm.add_include i1 407 cm.add_extend e1 408 cm.add_comment 'this is a comment', tl 409 410 loaded = Marshal.load "\x04\bU:\x16RDoc::NormalClass[\x0Fi\aI\"\nKlass" + 411 "\x06:\x06EFI\"\x15Namespace::Klass\x06;\x06FI" + 412 "\"\nSuper\x06;\x06Fo:\eRDoc::Markup::Document\a" + 413 ":\v@parts[\x06o;\a\a;\b[\x06o" + 414 ":\x1CRDoc::Markup::Paragraph\x06;\b" + 415 "[\x06I\"\x16this is a comment\x06;\x06F" + 416 ":\n@fileI\"\ffile.rb\x06;\x06F;\n0[\a[\nI" + 417 "\"\aa2\x06;\x06FI\"\aRW\x06;\x06F:\vpublicT@\x11" + 418 "[\nI\"\aa1\x06;\x06FI\"\aRW\x06;\x06F;\vF@\x11" + 419 "[\x06[\bI\"\aC1\x06;\x06Fo;\a\a;\b[\x00;\n0@\x11" + 420 "[\x06[\bI\"\aI1\x06;\x06Fo;\a\a;\b[\x00;\n0@\x11" + 421 "[\a[\aI\"\nclass\x06;\x06F[\b[\a;\v[\x00" + 422 "[\a:\x0Eprotected[\x00[\a:\fprivate[\x00[\aI" + 423 "\"\rinstance\x06;\x06F[\b[\a;\v[\x06[\aI" + 424 "\"\am1\x06;\x06F@\x11[\a;\f[\x00[\a;\r[\x00" + 425 "[\x06[\bI\"\aE1\x06;\x06Fo;\a\a;\b[\x00;\n0@\x11" 426 427 loaded.store = @store 428 429 assert_equal cm, loaded 430 431 inner = RDoc::Markup::Document.new( 432 RDoc::Markup::Paragraph.new('this is a comment')) 433 inner.file = tl 434 435 comment = RDoc::Markup::Document.new inner 436 437 assert_equal [a2, a1], loaded.attributes.sort 438 assert_equal comment, loaded.comment 439 assert_equal [c1], loaded.constants 440 assert_equal 'Namespace::Klass', loaded.full_name 441 assert_equal [i1], loaded.includes 442 assert_equal [e1], loaded.extends 443 assert_equal [m1], loaded.method_list 444 assert_equal 'Klass', loaded.name 445 assert_equal 'Super', loaded.superclass 446 assert_empty loaded.in_files 447 assert_nil loaded.parent 448 assert loaded.current_section 449 450 assert_equal tl, loaded.attributes. first.file 451 assert_equal tl, loaded.constants. first.file 452 assert_equal tl, loaded.includes. first.file 453 assert_equal tl, loaded.extends. first.file 454 assert_equal tl, loaded.method_list.first.file 455 456 expected = { nil => s0 } 457 assert_equal expected, loaded.sections_hash 458 end 459 460 def test_marshal_load_version_3 461 tl = @store.add_file 'file.rb' 462 463 ns = tl.add_module RDoc::NormalModule, 'Namespace' 464 465 cm = ns.add_class RDoc::NormalClass, 'Klass', 'Super' 466 cm.record_location tl 467 468 a1 = RDoc::Attr.new nil, 'a1', 'RW', '' 469 a1.record_location tl 470 a2 = RDoc::Attr.new nil, 'a2', 'RW', '', true 471 a2.record_location tl 472 473 m1 = RDoc::AnyMethod.new nil, 'm1' 474 m1.record_location tl 475 476 c1 = RDoc::Constant.new 'C1', nil, '' 477 c1.record_location tl 478 479 i1 = RDoc::Include.new 'I1', '' 480 i1.record_location tl 481 482 e1 = RDoc::Extend.new 'E1', '' 483 e1.record_location tl 484 485 section_comment = RDoc::Comment.new('section comment') 486 section_comment.location = tl 487 488 assert_equal 1, cm.sections.length, 'sanity, default section only' 489 s0 = cm.sections.first 490 s1 = cm.add_section 'section', section_comment 491 492 cm.add_attribute a1 493 cm.add_attribute a2 494 cm.add_method m1 495 cm.add_constant c1 496 cm.add_include i1 497 cm.add_extend e1 498 cm.add_comment 'this is a comment', tl 499 500 loaded = Marshal.load "\x04\bU:\x16RDoc::NormalClass[\x13i\bI\"\nKlass" + 501 "\x06:\x06ETI\"\x15Namespace::Klass\x06;\x06TI" + 502 "\"\nSuper\x06;\x06To:\eRDoc::Markup::Document\a" + 503 ":\v@parts[\x06o;\a\a;\b[\x06o" + 504 ":\x1CRDoc::Markup::Paragraph\x06;\b[\x06I" + 505 "\"\x16this is a comment\x06;\x06T:\n@fileI" + 506 "\"\ffile.rb\x06;\x06T;\n0[\a[\nI\"\aa2\x06;" + 507 "\x06TI\"\aRW\x06;\x06T:\vpublicT@\x11[\nI" + 508 "\"\aa1\x06;\x06TI\"\aRW\x06;\x06T;\vF@\x11" + 509 "[\x06U:\x13RDoc::Constant[\x0Fi\x00I\"\aC1\x06" + 510 ";\x06TI\"\x19Namespace::Klass::C1\x06;\x06T00o" + 511 ";\a\a;\b[\x00;\n0@\x11@\ac\x16RDoc::NormalClass0" + 512 "[\x06[\bI\"\aI1\x06;\x06To;\a\a;\b[\x00;\n0@\x11" + 513 "[\a[\aI\"\nclass\x06;\x06T[\b[\a;\v[\x00[\a" + 514 ":\x0Eprotected[\x00[\a:\fprivate[\x00[\aI" + 515 "\"\rinstance\x06;\x06T[\b[\a;\v[\x06[\aI" + 516 "\"\am1\x06;\x06T@\x11[\a;\r[\x00[\a;\x0E[\x00" + 517 "[\x06[\bI\"\aE1\x06;\x06To;\a\a;\b[\x00;\n0@\x11" + 518 "[\aU:\eRDoc::Context::Section[\bi\x000o;\a\a;\b" + 519 "[\x00;\n0U;\x0F[\bi\x00I\"\fsection\x06;\x06To" + 520 ";\a\a;\b[\x06o;\a\a;\b[\x06o;\t\x06;\b[\x06I" + 521 "\"\x14section comment\x06;\x06T;\n@\x11;\n0" + 522 "[\x06@\x11I\"\x0ENamespace\x06" + 523 ";\x06Tc\x17RDoc::NormalModule" 524 525 loaded.store = @store 526 527 assert_equal cm, loaded 528 529 inner = RDoc::Markup::Document.new( 530 RDoc::Markup::Paragraph.new('this is a comment')) 531 inner.file = tl 532 533 comment = RDoc::Markup::Document.new inner 534 535 assert_equal [a2, a1], loaded.attributes.sort 536 assert_equal comment, loaded.comment 537 assert_equal [c1], loaded.constants 538 assert_equal 'Namespace::Klass', loaded.full_name 539 assert_equal [i1], loaded.includes 540 assert_equal [e1], loaded.extends 541 assert_equal [m1], loaded.method_list 542 assert_equal 'Klass', loaded.name 543 assert_equal 'Super', loaded.superclass 544 assert_equal 'Namespace', loaded.parent.name 545 assert loaded.current_section 546 547 expected = { 548 nil => s0, 549 'section' => s1, 550 } 551 552 assert_equal expected, loaded.sections_hash 553 assert_equal [tl], loaded.in_files 554 555 assert_equal tl, loaded.attributes. first.file 556 assert_equal tl, loaded.constants. first.file 557 assert_equal tl, loaded.includes. first.file 558 assert_equal tl, loaded.extends. first.file 559 assert_equal tl, loaded.method_list.first.file 560 end 561 562 def test_merge 563 tl = @store.add_file 'one.rb' 564 p1 = tl.add_class RDoc::NormalClass, 'Parent' 565 c1 = p1.add_class RDoc::NormalClass, 'Klass' 566 567 c2 = RDoc::NormalClass.new 'Klass' 568 569 c2.merge c1 570 571 assert_equal 'Parent', c1.parent_name, 'original parent name' 572 assert_equal 'Parent', c2.parent_name, 'merged parent name' 573 574 assert c1.current_section, 'original current_section' 575 assert c2.current_section, 'merged current_section' 576 end 577 578 def test_merge_attributes 579 tl1 = @store.add_file 'one.rb' 580 tl2 = @store.add_file 'two.rb' 581 582 cm1 = RDoc::ClassModule.new 'Klass' 583 584 attr = cm1.add_attribute RDoc::Attr.new(nil, 'a1', 'RW', '') 585 attr.record_location tl1 586 attr = cm1.add_attribute RDoc::Attr.new(nil, 'a3', 'R', '') 587 attr.record_location tl1 588 attr = cm1.add_attribute RDoc::Attr.new(nil, 'a4', 'R', '') 589 attr.record_location tl1 590 591 cm2 = RDoc::ClassModule.new 'Klass' 592 # TODO allow merging when comment == '' 593 cm2.instance_variable_set :@comment, @RM::Document.new 594 595 attr = cm2.add_attribute RDoc::Attr.new(nil, 'a2', 'RW', '') 596 attr.record_location tl2 597 attr = cm2.add_attribute RDoc::Attr.new(nil, 'a3', 'W', '') 598 attr.record_location tl1 599 attr = cm2.add_attribute RDoc::Attr.new(nil, 'a4', 'W', '') 600 attr.record_location tl1 601 602 cm1.merge cm2 603 604 expected = [ 605 RDoc::Attr.new(nil, 'a2', 'RW', ''), 606 RDoc::Attr.new(nil, 'a3', 'W', ''), 607 RDoc::Attr.new(nil, 'a4', 'W', ''), 608 ] 609 610 expected.each do |a| a.parent = cm1 end 611 assert_equal expected, cm1.attributes.sort 612 end 613 614 def test_merge_attributes_version_0 615 tl1 = @store.add_file 'one.rb' 616 617 cm1 = RDoc::ClassModule.new 'Klass' 618 619 attr = cm1.add_attribute RDoc::Attr.new(nil, 'a1', 'RW', '') 620 attr.record_location tl1 621 attr = cm1.add_attribute RDoc::Attr.new(nil, 'a3', 'R', '') 622 attr.record_location tl1 623 attr = cm1.add_attribute RDoc::Attr.new(nil, 'a4', 'R', '') 624 attr.record_location tl1 625 626 cm2 = RDoc::ClassModule.new 'Klass' 627 # TODO allow merging when comment == '' 628 cm2.instance_variable_set :@comment, @RM::Document.new 629 630 attr = cm2.add_attribute RDoc::Attr.new(nil, 'a2', 'RW', '') 631 attr = cm2.add_attribute RDoc::Attr.new(nil, 'a3', 'W', '') 632 attr = cm2.add_attribute RDoc::Attr.new(nil, 'a4', 'W', '') 633 634 cm1.merge cm2 635 636 expected = [ 637 RDoc::Attr.new(nil, 'a1', 'RW', ''), 638 RDoc::Attr.new(nil, 'a2', 'RW', ''), 639 RDoc::Attr.new(nil, 'a3', 'RW', ''), 640 RDoc::Attr.new(nil, 'a4', 'RW', ''), 641 ] 642 643 expected.each do |a| a.parent = cm1 end 644 assert_equal expected, cm1.attributes.sort 645 end 646 647 def test_merge_collections_drop 648 tl = @store.add_file 'file' 649 650 cm1 = RDoc::ClassModule.new 'C' 651 cm1.record_location tl 652 653 const = cm1.add_constant RDoc::Constant.new('CONST', nil, nil) 654 const.record_location tl 655 656 cm2 = RDoc::ClassModule.new 'C' 657 cm2.record_location tl 658 659 added = [] 660 removed = [] 661 662 cm1.merge_collections cm1.constants, cm2.constants, cm2.in_files do |add, c| 663 if add then 664 added << c 665 else 666 removed << c 667 end 668 end 669 670 assert_empty added 671 assert_equal [const], removed 672 end 673 674 def test_merge_comment 675 tl1 = @store.add_file 'one.rb' 676 tl2 = @store.add_file 'two.rb' 677 678 cm1 = tl1.add_class RDoc::ClassModule, 'Klass' 679 cm1.add_comment 'klass 1', tl1 680 cm1.record_location tl1 681 682 cm2 = tl1.add_class RDoc::NormalClass, 'Klass' 683 cm2.add_comment 'klass 2', tl2 684 cm2.add_comment 'klass 3', tl1 685 cm2.record_location tl1 686 cm2.record_location tl2 687 688 cm2 = Marshal.load Marshal.dump cm2 689 cm2.store = @store 690 691 cm1.merge cm2 692 693 inner1 = @RM::Document.new @RM::Paragraph.new 'klass 3' 694 inner1.file = 'one.rb' 695 inner2 = @RM::Document.new @RM::Paragraph.new 'klass 2' 696 inner2.file = 'two.rb' 697 698 expected = @RM::Document.new inner2, inner1 699 700 assert_equal expected, cm1.comment 701 end 702 703 def test_merge_comment_version_0 704 tl = @store.add_file 'file.rb' 705 706 cm1 = RDoc::ClassModule.new 'Klass' 707 cm1.add_comment 'klass 1', tl 708 709 cm2 = RDoc::ClassModule.new 'Klass' 710 711 cm2.instance_variable_set(:@comment, 712 @RM::Document.new( 713 @RM::Paragraph.new('klass 2'))) 714 cm2.instance_variable_set :@comment_location, @RM::Document.new(cm2.comment) 715 716 cm1.merge cm2 717 718 inner = @RM::Document.new @RM::Paragraph.new 'klass 1' 719 inner.file = 'file.rb' 720 721 expected = @RM::Document.new \ 722 inner, 723 @RM::Document.new(@RM::Paragraph.new('klass 2')) 724 725 assert_equal expected, cm1.comment 726 end 727 728 def test_merge_constants 729 tl1 = @store.add_file 'one.rb' 730 tl2 = @store.add_file 'two.rb' 731 732 cm1 = tl1.add_class RDoc::ClassModule, 'Klass' 733 734 const = cm1.add_constant RDoc::Constant.new('C1', nil, 'one') 735 const.record_location tl1 736 const = cm1.add_constant RDoc::Constant.new('C3', nil, 'one') 737 const.record_location tl1 738 739 store = RDoc::Store.new 740 tl = store.add_file 'one.rb' 741 cm2 = tl.add_class RDoc::ClassModule, 'Klass' 742 cm2.instance_variable_set :@comment, @RM::Document.new 743 744 const = cm2.add_constant RDoc::Constant.new('C2', nil, 'two') 745 const.record_location tl2 746 const = cm2.add_constant RDoc::Constant.new('C3', nil, 'one') 747 const.record_location tl1 748 const = cm2.add_constant RDoc::Constant.new('C4', nil, 'one') 749 const.record_location tl1 750 751 cm1.merge cm2 752 753 expected = [ 754 RDoc::Constant.new('C2', nil, 'two'), 755 RDoc::Constant.new('C3', nil, 'one'), 756 RDoc::Constant.new('C4', nil, 'one'), 757 ] 758 759 expected.each do |a| a.parent = cm1 end 760 761 assert_equal expected, cm1.constants.sort 762 end 763 764 def test_merge_constants_version_0 765 tl1 = @store.add_file 'one.rb' 766 767 cm1 = tl1.add_class RDoc::ClassModule, 'Klass' 768 769 const = cm1.add_constant RDoc::Constant.new('C1', nil, 'one') 770 const.record_location tl1 771 const = cm1.add_constant RDoc::Constant.new('C3', nil, 'one') 772 const.record_location tl1 773 774 store = RDoc::Store.new 775 tl = store.add_file 'one.rb' 776 cm2 = tl.add_class RDoc::ClassModule, 'Klass' 777 cm2.instance_variable_set :@comment, @RM::Document.new 778 779 const = cm2.add_constant RDoc::Constant.new('C2', nil, 'two') 780 const = cm2.add_constant RDoc::Constant.new('C3', nil, 'two') 781 const = cm2.add_constant RDoc::Constant.new('C4', nil, 'two') 782 783 cm1.merge cm2 784 785 expected = [ 786 RDoc::Constant.new('C1', nil, 'one'), 787 RDoc::Constant.new('C2', nil, 'two'), 788 RDoc::Constant.new('C3', nil, 'one'), 789 RDoc::Constant.new('C4', nil, 'two'), 790 ] 791 792 expected.each do |a| a.parent = cm1 end 793 794 assert_equal expected, cm1.constants.sort 795 end 796 797 def test_merge_extends 798 tl1 = @store.add_file 'one.rb' 799 cm1 = tl1.add_class RDoc::ClassModule, 'Klass' 800 801 ext = cm1.add_extend RDoc::Extend.new('I1', 'one') 802 ext.record_location tl1 803 ext = cm1.add_extend RDoc::Extend.new('I3', 'one') 804 ext.record_location tl1 805 806 tl2 = @store.add_file 'two.rb' 807 tl2.store = RDoc::Store.new 808 809 cm2 = tl2.add_class RDoc::ClassModule, 'Klass' 810 cm2.instance_variable_set :@comment, @RM::Document.new 811 812 ext = cm2.add_extend RDoc::Extend.new('I2', 'two') 813 ext.record_location tl2 814 ext = cm2.add_extend RDoc::Extend.new('I3', 'one') 815 ext.record_location tl1 816 ext = cm2.add_extend RDoc::Extend.new('I4', 'one') 817 ext.record_location tl1 818 819 cm1.merge cm2 820 821 expected = [ 822 RDoc::Extend.new('I2', 'two'), 823 RDoc::Extend.new('I3', 'one'), 824 RDoc::Extend.new('I4', 'one'), 825 ] 826 827 expected.each do |a| a.parent = cm1 end 828 829 assert_equal expected, cm1.extends.sort 830 end 831 832 def test_merge_includes 833 tl1 = @store.add_file 'one.rb' 834 835 cm1 = tl1.add_class RDoc::ClassModule, 'Klass' 836 837 incl = cm1.add_include RDoc::Include.new('I1', 'one') 838 incl.record_location tl1 839 incl = cm1.add_include RDoc::Include.new('I3', 'one') 840 incl.record_location tl1 841 842 tl2 = @store.add_file 'two.rb' 843 tl2.store = RDoc::Store.new 844 845 cm2 = tl2.add_class RDoc::ClassModule, 'Klass' 846 cm2.instance_variable_set :@comment, @RM::Document.new 847 848 incl = cm2.add_include RDoc::Include.new('I2', 'two') 849 incl.record_location tl2 850 incl = cm2.add_include RDoc::Include.new('I3', 'one') 851 incl.record_location tl1 852 incl = cm2.add_include RDoc::Include.new('I4', 'one') 853 incl.record_location tl1 854 855 cm1.merge cm2 856 857 expected = [ 858 RDoc::Include.new('I2', 'two'), 859 RDoc::Include.new('I3', 'one'), 860 RDoc::Include.new('I4', 'one'), 861 ] 862 863 expected.each do |a| a.parent = cm1 end 864 865 assert_equal expected, cm1.includes.sort 866 end 867 868 def test_merge_includes_version_0 869 tl1 = @store.add_file 'one.rb' 870 871 cm1 = tl1.add_class RDoc::ClassModule, 'Klass' 872 873 incl = cm1.add_include RDoc::Include.new('I1', 'one') 874 incl.record_location tl1 875 incl = cm1.add_include RDoc::Include.new('I3', 'one') 876 incl.record_location tl1 877 878 tl2 = @store.add_file 'one.rb' 879 tl2.store = RDoc::Store.new 880 881 cm2 = tl2.add_class RDoc::ClassModule, 'Klass' 882 cm2.instance_variable_set :@comment, @RM::Document.new 883 884 incl = cm2.add_include RDoc::Include.new('I2', 'two') 885 incl = cm2.add_include RDoc::Include.new('I3', 'two') 886 incl = cm2.add_include RDoc::Include.new('I4', 'two') 887 888 cm1.merge cm2 889 890 expected = [ 891 RDoc::Include.new('I1', 'one'), 892 RDoc::Include.new('I2', 'two'), 893 RDoc::Include.new('I3', 'one'), 894 RDoc::Include.new('I4', 'two'), 895 ] 896 897 expected.each do |a| a.parent = cm1 end 898 899 assert_equal expected, cm1.includes.sort 900 end 901 902 def test_merge_methods 903 tl1 = @store.add_file 'one.rb' 904 tl2 = @store.add_file 'two.rb' 905 906 cm1 = tl1.add_class RDoc::NormalClass, 'Klass' 907 908 meth = cm1.add_method RDoc::AnyMethod.new(nil, 'm1') 909 meth.record_location tl1 910 meth = cm1.add_method RDoc::AnyMethod.new(nil, 'm3') 911 meth.record_location tl1 912 913 cm2 = RDoc::ClassModule.new 'Klass' 914 cm2.store = @store 915 cm2.instance_variable_set :@comment, @RM::Document.new 916 917 meth = cm2.add_method RDoc::AnyMethod.new(nil, 'm2') 918 meth.record_location tl2 919 meth = cm2.add_method RDoc::AnyMethod.new(nil, 'm3') 920 meth.record_location tl1 921 meth = cm2.add_method RDoc::AnyMethod.new(nil, 'm4') 922 meth.record_location tl1 923 924 cm1.merge cm2 925 926 expected = [ 927 RDoc::AnyMethod.new(nil, 'm2'), 928 RDoc::AnyMethod.new(nil, 'm3'), 929 RDoc::AnyMethod.new(nil, 'm4'), 930 ] 931 932 expected.each do |a| a.parent = cm1 end 933 934 assert_equal expected, cm1.method_list.sort 935 end 936 937 def test_merge_methods_version_0 938 tl1 = @store.add_file 'one.rb' 939 940 cm1 = tl1.add_class RDoc::NormalClass, 'Klass' 941 942 meth = cm1.add_method RDoc::AnyMethod.new(nil, 'm1') 943 meth.record_location tl1 944 meth = cm1.add_method RDoc::AnyMethod.new(nil, 'm3') 945 meth.record_location tl1 946 947 cm2 = RDoc::ClassModule.new 'Klass' 948 cm2.store = @store 949 cm2.instance_variable_set :@comment, @RM::Document.new 950 951 meth = cm2.add_method RDoc::AnyMethod.new(nil, 'm2') 952 meth = cm2.add_method RDoc::AnyMethod.new(nil, 'm3') 953 meth = cm2.add_method RDoc::AnyMethod.new(nil, 'm4') 954 955 cm1.merge cm2 956 957 expected = [ 958 RDoc::AnyMethod.new(nil, 'm1'), 959 RDoc::AnyMethod.new(nil, 'm2'), 960 RDoc::AnyMethod.new(nil, 'm3'), 961 RDoc::AnyMethod.new(nil, 'm4'), 962 ] 963 964 expected.each do |a| a.parent = cm1 end 965 966 assert_equal expected, cm1.method_list.sort 967 end 968 969 def test_merge_sections 970 store1 = @store 971 972 tl1_1 = store1.add_file 'one.rb' 973 974 cm1 = tl1_1.add_class RDoc::ClassModule, 'Klass' 975 cm1.record_location tl1_1 976 977 s1_0 = cm1.sections.first 978 s1_1 = cm1.add_section 'section 1', comment('comment 1', tl1_1) 979 cm1.add_section 'section 2', comment('comment 2 a', tl1_1) 980 cm1.add_section 'section 4', comment('comment 4 a', tl1_1) 981 982 store2 = RDoc::Store.new 983 tl2_1 = store2.add_file 'one.rb' 984 tl2_2 = store2.add_file 'two.rb' 985 986 cm2 = tl2_1.add_class RDoc::ClassModule, 'Klass' 987 cm2.record_location tl2_1 988 cm2.record_location tl2_2 989 990 cm2.sections.first 991 s2_2 = cm2.add_section 'section 2', comment('comment 2 b', tl2_1) 992 s2_3 = cm2.add_section 'section 3', comment('comment 3', tl2_2) 993 cm2.add_section 'section 4', comment('comment 4 b', tl2_2) 994 995 cm1.merge cm2 996 997 expected = [ 998 s1_0, 999 s1_1, 1000 s2_2, 1001 s2_3, 1002 RDoc::Context::Section.new(cm1, 'section 4', nil) 1003 ] 1004 1005 merged_sections = cm1.sections.sort_by do |s| 1006 s.title || '' 1007 end 1008 1009 assert_equal expected, merged_sections 1010 1011 assert_equal [comment('comment 2 b', tl2_1)], 1012 cm1.sections_hash['section 2'].comments 1013 1014 expected_s4_comments = [ 1015 comment('comment 4 a', tl2_1), 1016 comment('comment 4 b', tl2_2), 1017 ] 1018 1019 assert_equal expected_s4_comments, cm1.sections_hash['section 4'].comments 1020 end 1021 1022 def test_merge_sections_overlap 1023 store1 = @store 1024 1025 tl1_1 = store1.add_file 'one.rb' 1026 tl1_3 = store1.add_file 'three.rb' 1027 1028 cm1 = tl1_1.add_class RDoc::ClassModule, 'Klass' 1029 cm1.record_location tl1_1 1030 1031 cm1.add_section 'section', comment('comment 1 a', tl1_1) 1032 cm1.add_section 'section', comment('comment 3', tl1_3) 1033 1034 store2 = RDoc::Store.new 1035 tl2_1 = store2.add_file 'one.rb' 1036 tl2_2 = store2.add_file 'two.rb' 1037 tl2_3 = store2.add_file 'three.rb' 1038 1039 cm2 = tl2_1.add_class RDoc::ClassModule, 'Klass' 1040 cm2.record_location tl2_1 1041 cm2.record_location tl2_2 1042 1043 s2_0 = cm2.sections.first 1044 s2_1 = cm2.add_section 'section', comment('comment 1 b', tl1_1) 1045 cm2.add_section 'section', comment('comment 2', tl2_2) 1046 1047 cm1.merge_sections cm2 1048 1049 expected = [ 1050 s2_0, 1051 s2_1, 1052 ] 1053 1054 merged_sections = cm1.sections.sort_by do |s| 1055 s.title || '' 1056 end 1057 1058 assert_equal expected, merged_sections 1059 1060 expected = [ 1061 comment('comment 1 b', tl2_1), 1062 comment('comment 3', tl2_3), 1063 comment('comment 2', tl2_2), 1064 ] 1065 1066 comments = cm1.sections_hash['section'].comments 1067 1068 assert_equal expected, comments.sort_by { |c| c.file.name } 1069 end 1070 1071 def test_parse 1072 tl1 = @store.add_file 'one.rb' 1073 tl2 = @store.add_file 'two.rb' 1074 1075 cm = RDoc::ClassModule.new 'Klass' 1076 cm.add_comment 'comment 1', tl1 1077 cm.add_comment 'comment 2', tl2 1078 1079 doc1 = @RM::Document.new @RM::Paragraph.new 'comment 1' 1080 doc1.file = tl1 1081 doc2 = @RM::Document.new @RM::Paragraph.new 'comment 2' 1082 doc2.file = tl2 1083 1084 expected = @RM::Document.new doc1, doc2 1085 1086 assert_equal expected, cm.parse(cm.comment_location) 1087 end 1088 1089 def test_parse_comment 1090 tl1 = @store.add_file 'one.rb' 1091 1092 cm = RDoc::ClassModule.new 'Klass' 1093 cm.comment = comment 'comment 1', tl1 1094 1095 doc = @RM::Document.new @RM::Paragraph.new 'comment 1' 1096 doc.file = tl1 1097 1098 assert_equal doc, cm.parse(cm.comment) 1099 end 1100 1101 def test_parse_comment_format 1102 tl1 = @store.add_file 'one.rb' 1103 1104 cm = RDoc::ClassModule.new 'Klass' 1105 cm.comment = comment 'comment ((*1*))', tl1 1106 cm.comment.format = 'rd' 1107 1108 doc = @RM::Document.new @RM::Paragraph.new 'comment <em>1</em>' 1109 doc.file = tl1 1110 1111 assert_equal doc, cm.parse(cm.comment) 1112 end 1113 1114 def test_parse_comment_location 1115 tl1 = @store.add_file 'one.rb' 1116 tl2 = @store.add_file 'two.rb' 1117 1118 cm = tl1.add_class RDoc::NormalClass, 'Klass' 1119 cm.add_comment 'comment 1', tl1 1120 cm.add_comment 'comment 2', tl2 1121 1122 cm = Marshal.load Marshal.dump cm 1123 1124 doc1 = @RM::Document.new @RM::Paragraph.new 'comment 1' 1125 doc1.file = tl1 1126 doc2 = @RM::Document.new @RM::Paragraph.new 'comment 2' 1127 doc2.file = tl2 1128 1129 assert_same cm.comment_location, cm.parse(cm.comment_location) 1130 end 1131 1132 def test_remove_nodoc_children 1133 parent = @top_level.add_class RDoc::ClassModule, 'A' 1134 parent.modules_hash.replace 'B' => true, 'C' => true 1135 @store.modules_hash.replace 'A::B' => true 1136 1137 parent.classes_hash.replace 'D' => true, 'E' => true 1138 @store.classes_hash.replace 'A::D' => true 1139 1140 parent.remove_nodoc_children 1141 1142 assert_equal %w[B], parent.modules_hash.keys 1143 assert_equal %w[D], parent.classes_hash.keys 1144 end 1145 1146 def test_search_record 1147 @c2_c3.add_comment 'This is a comment.', @xref_data 1148 1149 expected = [ 1150 'C3', 1151 'C2::C3', 1152 'C2::C3', 1153 '', 1154 'C2/C3.html', 1155 '', 1156 "<p>This is a comment.\n" 1157 ] 1158 1159 assert_equal expected, @c2_c3.search_record 1160 end 1161 1162 def test_search_record_merged 1163 @c2_c3.add_comment 'comment A', @store.add_file('a.rb') 1164 @c2_c3.add_comment 'comment B', @store.add_file('b.rb') 1165 1166 expected = [ 1167 'C3', 1168 'C2::C3', 1169 'C2::C3', 1170 '', 1171 'C2/C3.html', 1172 '', 1173 "<p>comment A\n<p>comment B\n" 1174 ] 1175 1176 assert_equal expected, @c2_c3.search_record 1177 end 1178 1179 def test_store_equals 1180 # version 2 1181 loaded = Marshal.load "\x04\bU:\x16RDoc::NormalClass[\x0Fi\aI\"\nKlass" + 1182 "\x06:\x06EFI\"\x15Namespace::Klass\x06;\x06FI" + 1183 "\"\nSuper\x06;\x06Fo:\eRDoc::Markup::Document\a" + 1184 ":\v@parts[\x06o;\a\a;\b[\x06o" + 1185 ":\x1CRDoc::Markup::Paragraph\x06;\b" + 1186 "[\x06I\"\x16this is a comment\x06;\x06F" + 1187 ":\n@fileI\"\ffile.rb\x06;\x06F;\n0[\a[\nI" + 1188 "\"\aa2\x06;\x06FI\"\aRW\x06;\x06F:\vpublicT@\x11" + 1189 "[\nI\"\aa1\x06;\x06FI\"\aRW\x06;\x06F;\vF@\x11" + 1190 "[\x06[\bI\"\aC1\x06;\x06Fo;\a\a;\b[\x00;\n0@\x11" + 1191 "[\x06[\bI\"\aI1\x06;\x06Fo;\a\a;\b[\x00;\n0@\x11" + 1192 "[\a[\aI\"\nclass\x06;\x06F[\b[\a;\v[\x00" + 1193 "[\a:\x0Eprotected[\x00[\a:\fprivate[\x00[\aI" + 1194 "\"\rinstance\x06;\x06F[\b[\a;\v[\x06[\aI" + 1195 "\"\am1\x06;\x06F@\x11[\a;\f[\x00[\a;\r[\x00" + 1196 "[\x06[\bI\"\aE1\x06;\x06Fo;\a\a;\b[\x00;\n0@\x11" 1197 1198 loaded.store = @store 1199 1200 assert_same @store, loaded.store 1201 1202 a = loaded.attributes.first 1203 assert_same @store, a.store 1204 assert_same @store, a.file.store 1205 1206 c = loaded.constants.first 1207 assert_same @store, c.store 1208 assert_same @store, c.file.store 1209 1210 i = loaded.includes.first 1211 assert_same @store, i.store 1212 assert_same @store, i.file.store 1213 1214 e = loaded.extends.first 1215 assert_same @store, e.store 1216 assert_same @store, e.file.store 1217 1218 m = loaded.method_list.first 1219 assert_same @store, m.store 1220 assert_same @store, m.file.store 1221 end 1222 1223 def test_superclass 1224 assert_equal @c3_h1, @c3_h2.superclass 1225 end 1226 1227 def test_update_aliases_class 1228 n1 = @xref_data.add_module RDoc::NormalClass, 'N1' 1229 n1_k2 = n1.add_module RDoc::NormalClass, 'N2' 1230 1231 n1.add_module_alias n1_k2, 'A1', @xref_data 1232 1233 n1_a1_c = n1.constants.find { |c| c.name == 'A1' } 1234 refute_nil n1_a1_c 1235 assert_equal n1_k2, n1_a1_c.is_alias_for, 'sanity check' 1236 1237 n1.update_aliases 1238 1239 n1_a1_k = @xref_data.find_class_or_module 'N1::A1' 1240 refute_nil n1_a1_k 1241 assert_equal n1_k2, n1_a1_k.is_alias_for 1242 refute_equal n1_k2, n1_a1_k 1243 1244 assert_equal 1, n1_k2.aliases.length 1245 assert_equal n1_a1_k, n1_k2.aliases.first 1246 1247 assert_equal 'N1::N2', n1_k2.full_name 1248 assert_equal 'N1::A1', n1_a1_k.full_name 1249 end 1250 1251 def test_update_aliases_module 1252 n1 = @xref_data.add_module RDoc::NormalModule, 'N1' 1253 n1_n2 = n1.add_module RDoc::NormalModule, 'N2' 1254 1255 n1.add_module_alias n1_n2, 'A1', @xref_data 1256 1257 n1_a1_c = n1.constants.find { |c| c.name == 'A1' } 1258 refute_nil n1_a1_c 1259 assert_equal n1_n2, n1_a1_c.is_alias_for, 'sanity check' 1260 1261 n1.update_aliases 1262 1263 n1_a1_m = @xref_data.find_class_or_module 'N1::A1' 1264 refute_nil n1_a1_m 1265 assert_equal n1_n2, n1_a1_m.is_alias_for 1266 refute_equal n1_n2, n1_a1_m 1267 1268 assert_equal 1, n1_n2.aliases.length 1269 assert_equal n1_a1_m, n1_n2.aliases.first 1270 1271 assert_equal 'N1::N2', n1_n2.full_name 1272 assert_equal 'N1::A1', n1_a1_m.full_name 1273 end 1274 1275 def test_update_aliases_reparent 1276 l1 = @xref_data.add_module RDoc::NormalModule, 'L1' 1277 l1_l2 = l1.add_module RDoc::NormalModule, 'L2' 1278 o1 = @xref_data.add_module RDoc::NormalModule, 'O1' 1279 1280 o1.add_module_alias l1_l2, 'A1', @xref_data 1281 1282 o1_a1_c = o1.constants.find { |c| c.name == 'A1' } 1283 refute_nil o1_a1_c 1284 assert_equal l1_l2, o1_a1_c.is_alias_for 1285 refute_equal l1_l2, o1_a1_c 1286 1287 o1.update_aliases 1288 1289 o1_a1_m = @xref_data.find_class_or_module 'O1::A1' 1290 refute_nil o1_a1_m 1291 assert_equal l1_l2, o1_a1_m.is_alias_for 1292 1293 assert_equal 1, l1_l2.aliases.length 1294 assert_equal o1_a1_m, l1_l2.aliases[0] 1295 1296 assert_equal 'L1::L2', l1_l2.full_name 1297 assert_equal 'O1::A1', o1_a1_m.full_name 1298 end 1299 1300 def test_update_aliases_reparent_root 1301 store = RDoc::Store.new 1302 1303 top_level = store.add_file 'file.rb' 1304 1305 klass = top_level.add_class RDoc::NormalClass, 'Klass' 1306 object = top_level.add_class RDoc::NormalClass, 'Object' 1307 1308 const = RDoc::Constant.new 'A', nil, '' 1309 const.record_location top_level 1310 const.is_alias_for = klass 1311 1312 top_level.add_module_alias klass, 'A', top_level 1313 1314 object.add_constant const 1315 1316 object.update_aliases 1317 1318 assert_equal %w[A Klass Object], store.classes_hash.keys.sort 1319 1320 assert_equal 'A', store.classes_hash['A'].full_name 1321 assert_equal 'Klass', store.classes_hash['Klass'].full_name 1322 end 1323 1324 def test_update_includes 1325 a = RDoc::Include.new 'M1', nil 1326 b = RDoc::Include.new 'M2', nil 1327 c = RDoc::Include.new 'C', nil 1328 1329 @c1.add_include a 1330 @c1.add_include b 1331 @c1.add_include c 1332 @c1.ancestors # cache included modules 1333 1334 @m1_m2.document_self = nil 1335 assert @m1_m2.remove_from_documentation? 1336 1337 assert @store.modules_hash.key? @m1_m2.full_name 1338 refute @store.modules_hash[@m1_m2.full_name].nil? 1339 1340 @store.remove_nodoc @store.modules_hash 1341 refute @store.modules_hash.key? @m1_m2.full_name 1342 1343 @c1.update_includes 1344 1345 assert_equal [a, c], @c1.includes 1346 end 1347 1348 def test_update_includes_trim 1349 a = RDoc::Include.new 'D::M', nil 1350 b = RDoc::Include.new 'D::M', nil 1351 1352 @c1.add_include a 1353 @c1.add_include b 1354 @c1.ancestors # cache included modules 1355 1356 @c1.update_includes 1357 1358 assert_equal [a], @c1.includes 1359 end 1360 1361 def test_update_includes_with_colons 1362 a = RDoc::Include.new 'M1', nil 1363 b = RDoc::Include.new 'M1::M2', nil 1364 c = RDoc::Include.new 'C', nil 1365 1366 @c1.add_include a 1367 @c1.add_include b 1368 @c1.add_include c 1369 @c1.ancestors # cache included modules 1370 1371 @m1_m2.document_self = nil 1372 assert @m1_m2.remove_from_documentation? 1373 1374 assert @store.modules_hash.key? @m1_m2.full_name 1375 refute @store.modules_hash[@m1_m2.full_name].nil? 1376 @store.remove_nodoc @store.modules_hash 1377 refute @store.modules_hash.key? @m1_m2.full_name 1378 1379 @c1.update_includes 1380 1381 assert_equal [a, c], @c1.includes 1382 end 1383 1384 def test_update_extends 1385 a = RDoc::Extend.new 'M1', nil 1386 b = RDoc::Extend.new 'M2', nil 1387 c = RDoc::Extend.new 'C', nil 1388 1389 @c1.add_extend a 1390 @c1.add_extend b 1391 @c1.add_extend c 1392 @c1.each_extend do |extend| extend.module end # cache extended modules 1393 1394 @m1_m2.document_self = nil 1395 assert @m1_m2.remove_from_documentation? 1396 1397 assert @store.modules_hash.key? @m1_m2.full_name 1398 refute @store.modules_hash[@m1_m2.full_name].nil? 1399 @store.remove_nodoc @store.modules_hash 1400 refute @store.modules_hash.key? @m1_m2.full_name 1401 1402 @c1.update_extends 1403 1404 assert_equal [a, c], @c1.extends 1405 end 1406 1407 def test_update_extends_trim 1408 a = RDoc::Extend.new 'D::M', nil 1409 b = RDoc::Extend.new 'D::M', nil 1410 1411 @c1.add_extend a 1412 @c1.add_extend b 1413 @c1.each_extend do |extend| extend.module end # cache extended modules 1414 1415 @c1.update_extends 1416 1417 assert_equal [a], @c1.extends 1418 end 1419 1420 def test_update_extends_with_colons 1421 a = RDoc::Extend.new 'M1', nil 1422 b = RDoc::Extend.new 'M1::M2', nil 1423 c = RDoc::Extend.new 'C', nil 1424 1425 @c1.add_extend a 1426 @c1.add_extend b 1427 @c1.add_extend c 1428 @c1.each_extend do |extend| extend.module end # cache extended modules 1429 1430 @m1_m2.document_self = nil 1431 assert @m1_m2.remove_from_documentation? 1432 1433 assert @store.modules_hash.key? @m1_m2.full_name 1434 refute @store.modules_hash[@m1_m2.full_name].nil? 1435 1436 @store.remove_nodoc @store.modules_hash 1437 refute @store.modules_hash.key? @m1_m2.full_name 1438 1439 @c1.update_extends 1440 1441 assert_equal [a, c], @c1.extends 1442 end 1443 1444end 1445 1446